Delphi 2009 / indy 10 html email unicode problem

I have updating an email application to delphi 2009 from delphi 2006.
I now have the problem that html emails in in cyrrilic or greek are not send correctly. 

The code I used is:

        with IdMessage do
        begin
          clear;
          IsEncoded       := true;
          Charset         := 'utf-8';
          ContentType     :='multipart/alternative';
          Encoding        := meMime;

          UseNowForDate   := true;
          Subject         := MailSjabloon.Subject;
          From.Name       := MailSjabloon.AfzenderNaam;
          From.Address    := MailSjabloon.AfzenderEmail;
          Body.Clear;

          textpart := TIdText.Create( IdMessage.MessageParts );
          textpart.Body.Text := MailSjabloon.TextPagina;
          textpart.ContentType := 'text/plain';

          textpart := TIdText.Create( IdMessage.MessageParts);
          textpart.ContentType := 'text/html';
          textpart.Body.Text := MailSjabloon.HtmlPagina;
        end;

The text is not converted to utf-8, but is send as uft-16 (at least that is what I can see in the email program).
In the old situation the email was created as an utf8 string.

I think i am missing something, please help.

Greetings,

Bart
0
Bart
11/14/2008 9:09:16 AM
embarcadero.delphi.winsock 1874 articles. 2 followers. Follow

11 Replies
2572 Views

Similar Articles

[PageSpeed] 51

<Bart van Dijk> wrote in message news:43720@forums.codegear.com...

> The text is not converted to utf-8

That is because TIdMessage does not know that you want to do that.  The 
TIdMessage.CharSet property DOES NOT actually encode the message.  It only 
specifies the value of the "charset" attribute for the "Content-Type" header 
of the generated message data, and nothing else.  To do what you are asking, 
you need to also use the TIdMessage.OnInitializeISO event to tell TIdMessage 
which attributes to use for the actual encoding, ie:

{code}
with IdMessage do
begin
    ...
    Charset := 'utf-8';
    OnInitializeISO := DoInitializeISO;
    ...
end;
....
procedure TForm1.DoInitializeISO(var VHeaderEncoding: Char; var VCharSet: 
string);
begin
    VCharSet := 'UTF-8';
end;
{code}

I will update TIdMessage to use UTF-8 by default in D2009 when I have some 
free time to do so.

-- 
Remy Lebeau (TeamB)
0
Remy
11/14/2008 6:40:57 PM
Hi Remy,

Thanks for your swift reaction. 

I have added your code, but it did not solve the problem, the text is still send as utf-16.
0
Bart
11/17/2008 9:25:53 AM
test
Bart van Dijk a écrit :
> Hi Remy,
> 
> Thanks for your swift reaction. 
> 
> I have added your code, but it did not solve the problem, the text is still send as utf-16.
0
Utf
11/17/2008 9:38:38 AM
<Bart van Dijk> wrote in message news:44495@forums.codegear.com...

> I have added your code, but it did not solve the problem, the text is 
> still send as utf-16.

Then you will just have to set the CharSet values to 'utf-16' instead. 
Looking at Indy's source code, OnInitializeISO only applies to the message 
headers, not the message text.  I do not see any way to make Indy encode the 
text TO utf-8.  That functionality has not been added yet.

-- 
Remy Lebeau (TeamB)
0
Remy
11/17/2008 6:18:39 PM
That explains the problem, but does not solve it.

I tried with the encoding changed from UTF-8 to UTF-16, but that just results in the whole email message being unreadable.

I also tried without specifing a charset, and than I can read the englisch portion of the email, but the russian text is unreadable.

The problem is that for sending mails to russia you have to send in UTF-8 or better stil in Cyrrilic (KOI8-R) or the receiver can't read your message. Users of webmail in russia have the problem that most webmail programs can't even read UTF-8 messages.

My company does quite a lot of bussines with russia and eastern european countries, so this is quite an issue for us.

Is there a way to solve this in indy, or do I have to find another smtp email component?

Greetings,

Bart
0
Bart
11/21/2008 9:58:16 AM
<Bart van Dijk> wrote in message news:46482@forums.codegear.com...

> Is there a way to solve this in indy

Not unless you either:

1) re-write Indy manually to use AnsiString again instead of UnicodeString

2) add the missing encoding functionality

3) don't use TIdMessage.  Encode to a TStream manually, and then send that 
instead.  You can still use TIdSMTP for the base connection, but the data 
commands will have to be issued manually via SendCmd() and WriteLn()

> do I have to find another smtp email component?

Maybe.

-- 
Remy Lebeau (TeamB)
0
Remy
11/21/2008 5:37:55 PM
Hi,

Is there any news on when a unicode version of TIdSMTP will be available? A unicode enabled version of TIdPOP3 would also be very much appreciated.



Peter Vindstrup
0
Peter
2/4/2009 6:48:48 PM
Hi,

I just discovered that taking the latest source for the Indy components (from http://www.projectindy.org) helps a little. At least I'm now able to send the body part with the UTF-8 charset. Body the subject part of the TIdMessage still fails....

I can't really believe that Codegear would ship a version of the Indy components with Delphi 2009, that don't fully support unicode...



Peter Vindstrup
0
Peter
2/5/2009 9:51:21 AM
In Bulgaria we have the same problem. We use win1251. 
I tried your way with utf-8, but still not have any resolution.
I change  this in library :
procedure TIdMessage.DoInitializeISO(var VHeaderEncoding: Char; var VCharSet: string);
Begin
  VCharSet := 'UTF-8';
  if Assigned(FOnInitializeISO) then begin
    FOnInitializeISO(VHeaderEncoding, VCharSet);//APR
  end;
End


and this change:
function IdGetDefaultCharSet: TIdCharSet;

LANG_BULGARIAN : Result := idcswindows_1251; // or Result := idcsUNICODE_1_1;

but still not any resolution: 


 

This is my func. 

var IdSMTPExcept:TIdSMTP;
    IdMessageExcept: TIdMessage;
    wsData: WideString;
begin
    IdSMTPExcept    := TIdSMTP.Create(nil);
    IdMessageExcept := TIdMessage.Create(nil);
    try
        try
            IdSMTPExcept.Disconnect;
            IdMessageExcept.Clear;
            IdMessageExcept.ClearBody;
            IdMessageExcept.ClearHeader;
            IdMessageExcept.BccList.Clear;
            IdMessageExcept.CCList.Clear;
            IdMessageExcept.ClearBody;
            IdMessageExcept.MessageParts.Clear;
            IdMessageExcept.Clear;
            IdMessageExcept.IsEncoded:=True;
            IdMessageExcept.CharSet  :=  'UTF-8';
            IdMessageExcept.Encoding :=  meMime;
            IdSMTPExcept.Password    :=  sMailPass;
            IdSMTPExcept.Host := sSMTPHost;
            IdSMTPExcept.Port := iSMTPPort;
            IdSMTPExcept.Username := sMailAddress;
            IdMessageExcept.From.Address := sMailAddress;
            IdMessageExcept.Recipients.EMailAddresses := sMailRecipients;
            IdMessageExcept.Subject   := 'report ' +' '+DateToStr(Date);
            wsData :=   'здрасти';
            IdMessageExcept.Body.Text :=  wsData;
            IdSMTPExcept.AuthType := satNone;
            IdSMTPExcept.UseEhlo  := True;
            IdSMTPExcept.ReadTimeout    := 30000;
            {$IFDEF VER150}
            IdSMTPExcept.Connect(10000);
            {$ELSE}
            IdSMTPExcept.ConnectTimeout :=  10000;
            IdSMTPExcept.Connect;
            {$ENDIF}
            IdSMTPExcept.Send(IdMessageExcept);
            if IdSMTPExcept.Connected then
                IdSMTPExcept.Disconnect;
        except
            // Result := False;
            Exit;
        end;
    finally
        IdSMTPExcept.Free;
        IdMessageExcept.Free;
    end;
    // Result := True;
end;
0
forum1
5/3/2009 9:35:28 PM
Hello,

*Send Mail (with SSL)*
{code: delphi}
procedure TForm1.IdMessage_InitializeISO(var VHeaderEncoding: Char;
  var VCharSet: string);
begin
  VHeaderEncoding := 'B';
  VCharSet := 'UTF-8';
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  SMTP: TIdSMTP;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
  Msg : TIdMessage;
begin
  SMTP := TIdSMTP.Create(nil);
  try
    SMTP.Host     := 'smtp.gmail.com';
    SMTP.Port     := 587;
    SMTP.Username := 'hoge@gmail.com'; // UserName
    SMTP.Password := 'hogehoge';       // Password
    SSL := TIdSSLIOHandlerSocketOpenSSL.Create;
    try
      SSL.Host := SMTP.Host;
      SSL.Port := SMTP.Port;
      SSL.Destination := SSL.Host + ':' + IntToStr(SSL.Port);
      SMTP.IOHandler := SSL;
      SMTP.UseTLS := utUseExplicitTLS;
      SMTP.Connect;
      Msg := TIdMessage.Create(SMTP);
      try
        Msg.OnInitializeISO           := IdMessage_InitializeISO;
        Msg.ContentType               := 'text/plain';
        Msg.CharSet                   := 'UTF-8';
      //Msg.ContentTransferEncoding   := 'BASE64'; // BASE64 (7bit)
        Msg.ContentTransferEncoding   := '8bit';   // RAW(8bit)       
        Msg.From.Name                 := 'hoge@gmail.com';
        Msg.From.Address              := 'hoge@gmail.com';
        Msg.Recipients.EMailAddresses := 'hoge@gmail.com';
        Msg.Subject                   := 'Unicode String (subject)';
        Msg.Body.Text                 := 'Unicode String (body)'; // Please include the character of 0x80(U+0080) or later.
        SMTP.Send(Msg);
      finally
        Msg.Free;
      end;
      SMTP.Disconnect;
    finally
      SSL.Free;
    end;
  finally
    SMTP.Free;
  end;
end;
{code}

*Recv Mail (with SSL)*
{code: delphi}
procedure TForm1.Button2Click(Sender: TObject);
var
  POP3: TIdPOP3;
  SSL: TIdSSLIOHandlerSocketOpenSSL;
  Msg : TIdMessage;
  MsgCnt: Integer;
  BufLen,
  i,l: Integer;
  Body: UTF8String;
begin
  Memo1.Clear;
  POP3 := TIdPOP3.Create(nil);
  try
    POP3.Host     := 'pop.gmail.com';
    POP3.Port     := 995;
    POP3.Username := 'hoge@gmail.com'; // UserName
    POP3.Password := 'hogehoge';       // Password
    SSL := TIdSSLIOHandlerSocketOpenSSL.Create;
    try
      SSL.Host := POP3.Host;
      SSL.Port := POP3.Port;
      SSL.Destination := SSL.Host + ':' + IntToStr(SSL.Port);
      POP3.IOHandler := SSL;
      POP3.UseTLS := utUseImplicitTLS;
      POP3.Connect;
      Msg := TIdMessage.Create(nil);
      try
        MsgCnt := POP3.CheckMessages;
        for i:=1 to MsgCnt do
          begin
            POP3.Retrieve(i, Msg);
            Memo1.Lines.Add('Subject: ' + Msg.Subject);
            Memo1.Lines.Add('Body:');

            // NG
//          Memo1.Lines.Add(Msg.Body.Text);

            // OK
            BufLen := Length(Msg.Body.Text);
            SetLength(Body, BufLen);
            for l:=1 to Length(Msg.Body.Text) do
              Body[l] := AnsiChar(Ord(Msg.Body.Text[l]));
            Memo1.Lines.Add(String(Body));

          end;
      finally
        Msg.Free;
      end;
      POP3.Disconnect;
    finally
      SSL.Free;
    end;
  finally
    POP3.Free;
  end;
end;
{code}
When Body is 8bit, Trick is necessary.
7bit (UTF-8 with BASE64) has not problem.

# IndyTiburon.zip (2009/07/07)
--
Hideaki Tominaga
0
Hideaki
7/8/2009 8:44:42 PM
Just changed(replace) over 'ascii-us' with 'utf-8';) and everething is fine.
0
forum1
11/10/2010 3:08:03 PM
Reply:

Similar Artilces:

Converting Delphi 2007 Indy 10.2.3 to Delphi 2009 Indy 10.5.5 [Edit]
Hello, I am currently attempting to port over a Delphi 2007 project that uses Indy 10.2.3 (very successfully) to Delphi 2009 and Indy 10.5.5 (I just got the latest development build this morning). I think I am running into an encoding issue, but am not sure. Specifically, IDHTTP with SSL calls an old CGI and the CGI returns a .zip file and I then save it to the disk. In 2007 and before this worked perfectly. In 2009, it is not. Here is the examples of the 2 different results (though cut way short in the post) I am getting back: 2007: 'PK'#3#4#$14#0#0#0#8#0'rLQ9žrPb€'#0...

Problem with IdIPMCastClient Indy 10 Delphi 2009
Migrating an app from Delphi 2007 to Delphi 2009, I have run into a problem with IdIPMCastClient. Set Active to false raise exception 10049 cannot set address. Close the socket or reset socket you get either 10022 or 10038 If you disconnect and connect again by the 3rd time you will not receive any data. Having trouble updating to lastest dev snapshot. Any suggestions Regards Mike > {quote:title=Michael DuPree wrote:}{quote} > Migrating an app from Delphi 2007 to Delphi 2009, I have run into a problem with IdIPMCastClient. > Set Active to false raise exception 10049 cannot ...

Problem about Indy 10, IdTelnet component in Delphi 2009
Dear all: I make a simple test telnet program communicate with a linux server , through Idtelnet component , I specify the host property with a server ip, use a button to connect to the server . and display the welcome message in a memo . code as blew : procedure TForm1.Button1Click(Sender: TObject); begin Telnet.Connect; end; procedure TForm1.TelnetDataAvailable(Sender: TIdTelnet; const Buffer: string); begin Memo1.Lines.Add(Buffer); end; But when I click the button , the message displayed in the memo is like " }} }#}' ", not the normal...

Delphi 2009 and Indy 10 CharSet encoding problem
Hi guys, I'm sending some e-mails with my app, but the body text of my messages isnt displaying like expected ... example: I write some text with this characters ç ã é ó the text is changed to another char like "g". How can I fix that ? I've tryed to change the CharSet to Windows 1252 but nothing happened ... Any tips ? Regards, Diego Garcia -- Regards, Loki "Loki Man" <lokiman@hoknows.com> wrote in message news:51554@forums.codegear.com... > I've tryed to change the CharSet to Windows 1252 but noth...

Problems sending emails with attachments in Indy SMTP in Delphi 2009
Hi, I'm working with Delphi 2009 fully updated (12.0.3420.21218 with Update Pack 3), and I had the original version of the Indy 10.2.5. All attachments were going with a file name ATT000043.dat, instead of the correct name. I updated to the latest Indy from the Dev Snapshot, and it went to version 10.5.7. However, now the attachment does not appear as an attachment at all, the the message appears as: This is a multi-part message in MIME format --HF2WOHttwwLp1TZg=_wwY6H2qbRC0RDTyU Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Content-Disposition: inline H...

Indy E-Mail Problem (Indy 10, Delphi 2007)
Hello, we use Indy 10 with Delphi 2007 to get E-Mail using IMAP. We recieved an E-Mail which is not handled correctly. The E-Mail looks like this {code} Return-Path: <test@mail.com>; From: "Test Tester" <test@mail.com>; To: <test@mail.com>; Subject: Order Date: Wed, 7 Mar 2012 16:50:40 +0100 Message-ID: <15D526BEB8091D43859549D9E16E370FBA3123> MIME-Version: 1.0 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQFk6K6fcF3...

migrating from Delphi 6 With Indy 10 to XE7 with Indy 10
I updated the original Indy in D6 to version 10 several years ago. Now I want to migrate my application from D6 to XE7 and would like some feedback on the best route to take. I usually send data using readln and writeln statements. The data is typically XML format. Since migrating to XE7 will include potential unicode data what is the best approach to take when reading and writing data? Will writeln and readln work in these cases or should I be using a different strategy to send unicode data between the tidtcpclient and tidtcpserver applications? al wrote: > I usually send data ...

Problems with MSHTML_TLB on Delphi 2009(Unicode)
The first error I got when I add mshtml_tlb to the uses clause was "file not found: mshtml_tlb.dcu", so I tried to import and install the scriptlet (mshtml_tlb) component. After I imported and installed the component I now get about fifty errors like "IHTML... redeclared". Yep, they were all redeclaration issues. I am using delphi unicode, how can I get around this? Thanks in advance. > The first error I got when I add mshtml_tlb to the uses clause was > "file not found: mshtml_tlb.dcu", so I tried to import and install > the scriptlet (mshtml_tlb) co...

Indy IdHMACSHA1 different results in Delphi 2007 and Delphi 2009
Hello newsgroup A test of the IdHMACSHA1 encryption method shows different results, and I am not sure if there is an error in my code or in the Indy code shipped with Delphi 2009. The Delphi 2007 version works in an application which communicates with Amazon Web Services and so it seems to be the correct one. Any suggestions are very welcome, maybe I just need to download a newer version of Indy? program Test; {$APPTYPE CONSOLE} uses IdHMACSHA1, IdCoderMIME, IdGlobal, SysUtils; function Base64Encode(const Input: string): string; begin Result := TIdEncode...

Problems
Hi; We have a software developed in the Delphi 2009 and we do NOT use the runtime themes. So, the option: Projetct / Options / Application / Enable Runtime Themes is UNCHECKED. When I'm on the Delphi 2009, it's all right. The problem is when I use the Delphi 2010. The same configuration (Projetct / Options / Application / Enable Runtime Themes is UNCHECKED). The form editor (IDE) insists on show the forms with the current Windows theme. I don't like this, I want the runtime themes off while I'm programming and editing my forms. How can I solve it? Thanks to...

Indy 10.6 compilation with Delphi 2009
With the current Subversion branch, the Delphi 2009 compiler shows these errors: C:\Delphi\indy-10.6\Lib\System\IdStackWindows.pas(287) Error: E2137 Method 'GetSocketOption' not found in base class C:\Delphi\indy-10.6\Lib\System\IdStackWindows.pas(289) Error: E2137 Method 'SetSocketOption' not found in base class C:\Delphi\indy-10.6\Lib\System\IdStackWindows.pas(322) Fatal: F2063 Could not compile used unit 'IdIDN.pas' TIdStackWindows in System\IdStackWindows.pas, Lines 287 to 290: procedure GetSocketOption(ASocket: TIdStackSocketHandle; ALevel...

Indy 10 install problem / Delphi 2006
I recently did a wipe-and-reinstall on my PC. I installed Delphi 2006 and now I am trying to install the newer version of Indy10 as the one that comes with the Delphi 2006 install has bugs. I followed the instructions I found here: http://www.indyproject.org/Sockets/Docs/Indy10Installation.EN.aspx and I downloaded the new version from here: http://indy.fulgan.com/ZIP/indy10.zip I unzipped the relevant directories into a new subdirectory I created under C:\Program Files\Borland\BDS\4.0\source\Indy10New\Lib When I began step 3, which says "Now open these .dpk files and click install...

Delphi 5 To Delphi 2009
I upgraded to Delphi 2009 from D5. The install says I can install Delphi and/or C++. Delphi installed OK but I see nothing of C++. What am I missing or does my upgrade not include C++? Thanks It depends on what you bought. If you bought Delphi 2009 only, that's what you get. If you bought Delphi 2009 and C++ Builder 2009 you get both. My guess is you got Delphi 2009 only. The simplest way to verify is look your invoice - it should say I would think. You could also go to members.embarcadero.com, login, then click on my registered products. There will be a textual description of...

Delphi 4 to Delphi 2009
Hello, Thanks to all who answered my previous question. That was a great help. And atlast our client agreed to upgrade our delphi version from 4 to Delphi 2009. *Sigh*. But before that, I need to give the estimation and cost regarding the migration to delphi 2009. Can anyone tell me is there any tool to migrate from delphi 4 to delphi 2009 or just I need to compile our Delphi 4 application in Delphi 2009. I have read from the delphi 2009 feature matrix that Delphi 1 through Delphi 2007 import is possible in delphi 2009. But i am not that sure considering the size of our application. ...

Web resources about - Delphi 2009 / indy 10 html email unicode problem - embarcadero.delphi.winsock

UnicodeNepali.com - Unicode Nepali Converter and Tools
Unicode Nepali Converter. Unicode Nepali typing with any standard keyboard. Simply type in Roman and it will convert into Unicode Nepali. Won't ...

Search form - searching for Unicode characters by name
For example, searching for ampersand finds U+0026 AMPERSAND as well as other ampersand characters.Searching for coptic finds letters with COPTIC ...

Unicode Consortium
Welcome! The enables people around the world to use computers in any language. Our freely-available specifications and data form the foundation ...

Mapping of Unicode characters - Wikipedia, the free encyclopedia
, or hexadecimal 110000 code points). As of Unicode 6.2, released in September 2012, 249,764 (22.4%) of these code points are assigned, including ...

Unicode - Wikipedia, the free encyclopedia
This article contains special characters . Without proper rendering support , you may see question marks, boxes, or other symbols . Unicode is ...

Symbol Keyboard - Unicode Icons Signs,Characters Symbols,Emoji Art for Texting on the App Store on iTunes ...
Get Symbol Keyboard - Unicode Icons Signs,Characters Symbols,Emoji Art for Texting on the App Store. See screenshots and ratings, and read customer ...

Unicode Consortium approves 36 new emoji including selfie, bacon, face palm
... good news for those who have a face palm moment or need to express their love of bacon or selfies &#8212; new emoji are on their way. The Unicode ...

Unicode Consortium approves 36 new emoji including selfie, bacon, face palm
... good news for those who have a face palm moment or need to express their love of bacon or selfies &#8212; new emoji are on their way. The Unicode ...

Unicode Consortium
Your guide to the best in tech.

Black emoji may finally be on the way, Unicode report reveals
Note: The CBC does not necessarily endorse any of the views posted. By submitting your comments, you acknowledge that CBC has the right to reproduce, ...

Resources last updated: 12/24/2015 4:56:47 AM