How to send Greek characters email using TIdMessage and Delphi XE * UPDATED *

We want to send the following htm file as body: via D-XE and Indy TIdMessage components

 <html> <head> <meta http-equiv=Content-Type content="text/html; charset=windows-1253"> <meta name=Generator content="Microsoft Word 12 (filtered)"> <style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman","serif"; color:black;} .MsoChpDefault {font-size:10.0pt;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style> </head> <body bgcolor=white lang=EL> <div class=Section1> <p class=MsoNormal><span lang=EN-US style='font-family:"Tahoma","sans-serif"'>Abcd</span><span lang=EN-US style='font-family:"Tahoma","sans-serif"'> </span><span style='font-family:"Tahoma","sans-serif"'>αβγδ ά&#8118;&#8048;&#7938; </span></p> </div> </body> </html> 

(Well, the actual file is different, but the problem is the same).

In the above file, if you save it as temp.htm and upload it to Internet Explorer, you will see 4 Latin characters, 4 Greek characters without a tone and 4 Greek characters with a tone (Alpha variants are the first letter of the Greek alphabet). Something like that:

Abcd αβγδ άᾶὰἂ

So far so good.

If we upload the above file to the TIdMessage property of the TIdMessage and send it by email, it will look like this:

Abcd ????? ᾶὰἂ

As you can see, the Greek letters from the monotonous alphabet are replaced by ????? - Tested with Mozilla Thunderbird 3 on WinXP.

The properties of the TIdMessage component TIdMessage as follows:

TIdMessage Properties

I tried installing CharSet on Windows-1253 , but no luck.

Any ideas how this might work?

UPDATE:

Answering your questions:

Source of the raw message after it was received: (email addresses have been edited)

 From - Thu Sep 15 11:11:06 2011 X-Account-Key: account3 X-UIDL: 00007715 X-Mozilla-Status: 0001 X-Mozilla-Status2: 00400000 X-Mozilla-Keys: Return-Path: [redacted] X-Envelope-To: [redacted] X-Spam-Status: No, hits=0.0 required=5.0 tests=AWL: 0.194,BAYES_20: -0.73,HTML_MESSAGE: 0.001, MIME_HEADER_CTYPE_ONLY: 0.56,MIME_HTML_ONLY: 0.001,MISSING_MID: 0.001, CUSTOM_RULE_FROM: ALLOW,TOTAL_SCORE: 0.027,autolearn=no X-Spam-Level: Received: from localhost ([127.0.0.1]) by [redacted] for [redacted]; Thu, 15 Sep 2011 11:10:59 +0300 From: [redacted] Subject: Test msg To: [redacted] Content-Type: text/html; charset=us-ascii Sender: [redacted] Reply-To: [redacted] Disposition-Notification-To: [redacted] Return-Receipt-To: [redacted] Date: Thu, 15 Sep 2011 11:10:59 +0300 <html> <head> <meta http-equiv=Content-Type content="text/html; charset=windows-1253"> <meta name=Generator content="Microsoft Word 12 (filtered)"> <style> <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Tahoma; panose-1:2 11 6 4 3 5 4 4 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman","serif"; color:black;} .MsoChpDefault {font-size:10.0pt;} @page Section1 {size:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt;} div.Section1 {page:Section1;} --> </style> </head> <body bgcolor=white lang=EL> <div class=Section1> <p class=MsoNormal><span lang=EN-US style='font-family:"Tahoma","sans-serif"'>Abcd</span><span lang=EN-US style='font-family:"Tahoma","sans-serif"'> </span><span style='font-family:"Tahoma","sans-serif"'>???? ?&#8118;&#8048;&#7938; </span></p> </div> </body> </html> 

Mozilla Thunderbird also says Message Encoding: Western (ISO-8859-1) . I tried to put different encodings in the IdMessage tag, such as windows-1253 (Greek) or UTF-8 - the result was the same. Also, I tried converting the htm file to UTF-8 (using Notepad ++) - it looked the same (I changed the encoding manually in html meta info). Sent a message again. Result: Abcd ??? 2? 3 ???? ᾶὰἂ

+4
source share
3 answers

If you look at your own screenshots, you will see that TIdMessage and the sent message will both use US-ASCII as CharSet. This is why your data is changing.

If you load HTML into the TIdMessage.Body or TIdText.Body , you must decode the data before UTF-16 (since this Body property is used in XE), then set TIdMessage.CharSet or TIdText.CharSet to windows-1253 , so the data UTF-16 correctly transcoded when sending an email, for example:

 Enc := CharsetToEncoding('windows-1253'); try IdMessage.Body.LoadFromFile('file.htm', Enc); IdMessage.ContentType := 'text/html'; IdMessage.CharSet := 'windows-1253'; finally Enc.Free; end; 

Or:

 Enc := CharsetToEncoding('windows-1253'); try with TIdText.Create(IdMessage.MessageParts, nil) do begin Body.LoadFromFile('file.htm', Enc); ContentType := 'text/html'; CharSet := 'windows-1253'; end; finally Enc.Free; end; 

If instead you load HTML into a TIdAttachment object, you do not need to decode / encode anything manually, as the attachment data is sent as is.

 with TIdAttachmentFile.Create(IdMessage.MessageParts, 'file.htm') do begin ContentType := 'text/html'; end; 
+3
source

Try setting ContentTransferEncoding, for example, for citation-printing. Remember that mail still uses 7-bit charcters (unless the server advertises it, it can process 8-bit or binary data), so proper transmission encoding is required.

0
source

I am using Indy 10 and Delphi XE2 (Unicode std Strings) setting the CharSet message to "ISO-8859-7" and adding text to the body using UTF8Encode

TempMess := TIdMessage.Create(self); TempMess.CharSet :='ISO-8859-7'; TempMess.Body.Add(UTF8Encode('Καλημέρα!!!'));

0
source

All Articles