Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Nov 12, 2018 9:34 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Problem to manipulate (SMTP) email headers (SOLVED)
PostPosted: Fri Jul 08, 2011 9:42 am 
Offline

Joined: Tue Mar 22, 2011 4:46 am
Posts: 28
Hi,

I'm trying to create a method that sends emails using SMTP Secure Socket. The method must support emails with attachments and multi language text.

But I'm stuck at the last part of my method, where I need to define the needed headers in order to send a non simple ascii text, like greek characters (iso-8859-7).
I tried the obvious solution (at least for me):
mailToSend.Headers.AppendHeader "Content-Type", "text/plain; charset=iso-8859-7"


Testing: In gmail and hotmail I get the email (sent by my application) correctly. It displayes the greek characters just fine.
But when I try to receive and read the email through Outlook, I see only weird symbols (αβγδΡ΢ηθικλμνξοΟ)

After studying emails with greek characters sent by other applications I try to add the below header:
mailToSend.Headers.AppendHeader "Content-Type", "multipart/alternative; boundary=_Some_Boundary_Text_"

and then add at the end of the header the followings:

--_Some_Boundary_Text_
mail1.Headers.AppendHeader "Content-Type", "text/plain; charset=iso-8859-7"
mail1.Headers.AppendHeader "Content-Transfer-Encoding", "quoted-printable"

--_Some_Boundary_Text_
mail1.Headers.AppendHeader "Content-Type", "text/plain; charset=iso-8859-7"
mail1.Headers.AppendHeader "Content-Transfer-Encoding", "quoted-printable"

--_Some_Boundary_Text_


Is this the correct approach? If yes how can I add a new line and then the caption "--_Some_Boundary_Text_" in the header?
AppendHeader does not allow me to do so?

If there is a better/correcter approach please please please let me know!

Thanks in advance!

rb 2011 r2 on Windows 7


Last edited by georget on Thu Jul 14, 2011 9:15 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Problem to manipulate (SMTP) email headers
PostPosted: Fri Jul 08, 2011 1:36 pm 
Offline

Joined: Mon Jul 24, 2006 4:06 am
Posts: 274
Hi,

do you have problems with Outlook Windows or Mac? Which version?

Mails may have a hierarchical structure. Setting text/plain should be sufficient, if you don't have attachments. Multipart/alternative is used if you have text with plain and html representation. So this is not the correct header for your mail.

Have you tried using html? How does the raw text appear in Outlook?

Regards

Beatrix Willius

_________________
Mit freundlichen Grüßen/Regards

Trixi Willius

http://www.mothsoftware.com
Mail Archiver X: The email archiving solution for professionals


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem to manipulate (SMTP) email headers
PostPosted: Fri Jul 08, 2011 5:00 pm 
Offline

Joined: Thu Dec 16, 2010 1:22 pm
Posts: 188
I had a similar problem a while back trying to send emails via the rapidfax service. It turns out, they expected a charset to be specified, as in
Quote:
Content-type: text/plain;charset="iso-8859-1"
which I later discovered is a VERY standard part of email headers, if not technically even required!
But RS doesn't do that. As soon as you add plain text or html text to the body property, it would wrap it like so
Quote:
Content-Type: multipart/alternative; boundary="e2dlh5sna0qz"
--e2dlh5sna0qz
Content-type: text/plain;
Content-transfer-encoding: 7bit
PL:test body
--e2dlh5sna0qz
Content-type: text/html;
Content-transfer-encoding: 7bit
HT:test body
--e2dlh5sna0qz--

but where's the charset??
I went round and round trying to fight the headers to make them cooperate, I even tried modifying the raw-source of the email message with the .source property, but when you sent it, it decided it was smarter and reverted back to the wrong headers.

Ah.... but I would not be defeated! If setting the body text is what was screwing up the message, then the simple solution is don't set the body text.
WHAT?? What good is an email without the body text.
Well, you don't technically set the body text with what you want the body to be, instead you create the entire raw email yourself.
Like so:
em=new EmailMessage

em.Headers.SetHeader("MIME-Version","1.0")
em.Headers.SetHeader("Content-Type","multipart/mixed; boundary="+chr(34)+"fkdn2yqmpt4k"+chr(34)+endofline+endofline+"--fkdn2yqmpt4k")

em.FromAddress=myemail
em.Subject=emailmod.subject

// attach a file
fbin=BinaryStream.Open(filetoemail)
fname=filetoemail.Name
s="--fkdn2yqmpt4k"+EndOfLine _
+"Content-type: text/plain;charset="+chr(34)+"iso-8859-1"+chr(34)+EndOfLine _
+"Content-transfer-encoding: 7bit"+EndOfLine _
+EndOfLine _
+emailbodytext+endofline _ // here's the body of your email
+EndOfLine _
+EndOfLine _
+"--fkdn2yqmpt4k"+EndOfLine _
+"Content-Type: application/pdf; name="+chr(34)+fname+chr(34)+endofline _ // here's an attachment
+"Content-Disposition: attachment; filename="+chr(34)+fname+chr(34)+endofline _
+"Content-Transfer-Encoding: base64"+EndOfLine _
+EndOfLine _
+EncodeBase64(fbin.Read(filetoemail.Length))+EndOfLine _
+EndOfLine _
'+"--fkdn2yqmpt4k--"
fbin.Close
em.AddRecipient emailrecpt
if ccself then
em.AddCCRecipient myemail
end

s=s+"--fkdn2yqmpt4k--"

em.BodyPlainText=s // we've been building this long string containing the entire email source, no now set it to the body.

es.Messages.Append em

es.SendMail


Ah, but wait, you say, I thought setting the body caused the loss of the charset in the header???
Actually it did, but since we wrapped it all in a multipart message, it's ok, here's how the source comes out.

Quote:
MIME-Version: 1.0 (we added this)
Content-type: multipart/mixed; boundary="fkdn2yqmpt4k" (and this)
--fkdn2yqmpt4k (we specified our own boundary string)
Content-transfer-encoding: 7bit (here's the part that RS screwed up by setting the bodytext, but we don't care because of how we wrapped it)
--fkdn2yqmpt4k
Content-type: text/plain;charset="iso-8859-1" (here's our "fake" body text, formatted just how it should be)
Content-transfer-encoding: 7bit
This is the body of the email


--fkdn2yqmpt4k
Content-Type: application/pdf; name="filename.pdf" (here's our attachment)
Content-Disposition: attachment; filename="filename.pdf"
Content-Transfer-Encoding: base64

JVBERi0xLjMNJeLjz9MNMSAwIG9iaiA8PCAvVHlwZSAvQ2F0YWxvZyAvUGFnZXMgMiAwIFIgPj4g.............

--fkdn2yqmpt4k--


And everyone is happy :)

Whew! So there you go. You can bend RS email into submission and set whatever headers and encoding you want!
Good luck


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem to manipulate (SMTP) email headers
PostPosted: Tue Jul 12, 2011 4:06 am 
Offline

Joined: Tue Mar 22, 2011 4:46 am
Posts: 28
Thank you for your replies

jlawrence your idea to write the raw email is brilliant. And you explain everything really very well :)
Unfortunately your method still does not work in my application. As before, I get the greek characters and the attachments correctly in a hotmail/gmail account.
But through outlook I don't get it correctly. Actually now I don't get at all any character or attachment file :(

Beatrix Willius I'm working in Windows 7, and currently I'm using Outlook 2003.
I didn't try the HTML way because my initial requirement was the mail to be sent as plain text.
But I'll try also HTML just to see if it works.


Top
 Profile  
Reply with quote  
 Post subject: Re: Problem to manipulate (SMTP) email headers (SOLVED)
PostPosted: Thu Jul 14, 2011 9:27 am 
Offline

Joined: Tue Mar 22, 2011 4:46 am
Posts: 28
After some thousands of tries, I managed to solve my initial issue which was to send other than english characters (tested with greek ones) succesfully.
As mentioned above, I was able to read the greek characters from gmail/hotmail but not from Microsoft Outlook.

The solution is in the Content-Type Header.
I was trying
mail1.Headers.AppendHeader "Content-Type", "text/plain; charset=iso-8859-1;"

OR
mail1.Headers.AppendHeader "Content-Type", "text/plain; charset=iso-8859-7;"


But once I used utf-8 everything was readable :)
mail1.Headers.AppendHeader "Content-Type", "text/plain; charset=UTF-8;"


Actually I thought iso-8859-1 and UTF-8 was the same.

I tested it with attachments and text that contains mixed english and greek characters.
Test is done only on Windows.
Hope this will help other RS users :)

rb 2011 r2 on Windows 7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group