I’m having a hard time encoding my email body and subject.
whatever I encode, the are missrepresented. It appears as if it where re-encoded further down the line.
My code:
emails are supposed to contain ASCII only, pretty much. If you want to send UTF8 you need to encode things such as the subject lines as Beatrix suggests. See here:
The same applies to the body of your mail, you’ll have to encode it as base64 or quoted-printable, and send a Content-Transfer-Encoding: header (see the MIME reference above) to tell the other end what you’ve done. I’ve not looked at the Xojo email class, so I don’t know what it supports regarding all this. For my email client, written in Xojo, I handled all this myself.
// Create EmailMessage
Dim mail As New EmailMessage
mail.Headers.AppendHeader(“Mime-Version:”,“1.0”) // for subject line
mail.Headers.AppendHeader(“Content-Transfer-Encoding:”, “quoted-printable”) // for body
mail.FromAddress = “info@xxx.ch”
mail.AddRecipient(sMailTo)
mail.Subject = “= ?iso-8859-1?Q?” + EncodeForMail(sSubject) + “?=” // Subject needs start and end for encoding
mail.BodyPlainText = EncodeForMail(sMessage)
// Send it
MailSocket.Messages.Append(mail)
MailSocket.SendMail[/code]
then the method that does the encoding:
[code]Public Function EncodeForMail(sEMailText as string) as String
// encode
// disassemble to Characters
Var chArray() As String
chArray = sEMailText.Split("") // produces array of individual characters
for i as integer = 0 to chArray.Ubound
select case chArray(i)
case “”
chArray(i) = “=C4”
case “”
chArray(i) = “=E4”
case “”
chArray(i) = “=F6”
case “”
chArray(i) = “=D6”
case “”
chArray(i) = “=DC”
case “”
chArray(i) = “=FC”
'…
'case else // all others stay untouched
end select
Why don’t you use one of the methods Xojo provides for encoding such as EncodeBase64 or EncodeQuotedPrintable? Then you won’t need to write your own method.