Search results for 'TIdMessage'. 3 post(s) found.

  1. 2009/07/20 How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
  2. 2009/07/16 How to encode subject content when sending mail with TIdMessage ?
  3. 2009/07/07 How to send email by TIdSMTP VCL ?
2009/07/20 10:22

How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL


I had problem in encoding mail header with IdSMTP, IdMessage. I found some references in Internet, but the problem is the delivered mail subject is always filled with question marks except english letters.

I found the answer to clear the problem. Here's the answer for above problem
{
  Programmed 2009
  by Chunun Kang (kurapa@kurapa.com)
}

uses ..... , IdSMTP, IdMessage, IdCoderMIME; // must be added

procedure TMainFrm.DoInitializeISO(var VHeaderEncoding: Char; var VCharSet:string);
begin
  VHeaderEncoding := 'B';
  VCharSet := 'UTF-8';
end;

procedure TMainFrm.KMAIL( sTo, title, body:string);
var
  IdMsg : TIdMessage;

  function Base64Encode(const Text : utf8string): string;
  var
    Encoder : TIdEncoderMime;
  begin
    Encoder := TIdEncoderMime.Create(nil);
    try
      Result := Encoder.EncodeBytes( TBytes(Text));
    finally
      FreeAndNil(Encoder);
    end
  end;
begin
  IdMsg := TIdMessage.Create(nil);
  try
    with TIdSMTP.Create(nil) do
    try
      UserName := SMTPFrm.m_username.Text;
      Password := SMTPFrm.m_password.Text;
      Host := SMTPFrm.m_host.Text;

      IdMsg.OnInitializeISO := DoInitializeISO;
      IdMsg.ContentType := 'text/html';
      IdMsg.CharSet := 'UTF-8';
      IdMsg.ContentTransferEncoding := 'BASE64';

      IdMsg.Body.Add(body);
      IdMsg.Recipients.emailAddresses := sTo;

      // The mail subject must be encoded in mail header as below.
      IdMsg.Subject := '=?UTF-8?b?' + Base64Encode(ansitoutf8(title)) + '?=';

      // string type address must be given. ex) kurapa@kurapa.com
      IdMsg.From.Address := SMTPFRm.m_email.Text;
      // string type address must be given. ex) Chunun Kang
     IdMsg.From.Name := SMTPFRm.m_realname.Text

      Connect;
      Send(IdMsg);
      Disconnect;
    finally
      Free;
    end;
  finally
    IdMsg.free;
  end;
end;

procedure TMainFrm.Button2Click(Sender: TObject);
begin
  KMAIL( 'kurapa@kurapa.com', 'Message Text in Korean - 한글로 보내는 메일', '제대로 <font color=green>메일</font>이 보내지는지 궁금합니다.');
end;

In above example, the application is trying to send email in Korea, and the result is successful.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2009/07/16 16:35

How to encode subject content when sending mail with TIdMessage ?


Today, I tried to develop mail application with TIdMessage, but I have problem in character set encoding. And I found the answer at http://www.yac.com.pl/mt.texts.tidmessage.charset.en.html

With this wrapper class,
  TMyMessage = class(TIdMessage)
  private
    procedure InitializeUTF8(
                var VTransferHeader: TTransfer; var VHeaderEncoding: char; var VCharSet: string);
  end;
 
  procedure TMyMessage.InitializeUTF8(
    var VTransferHeader: TTransfer; var VHeaderEncoding: char; var VCharSet: string);
  begin
    VCharSet := 'UTF-8';
  end;

And then,
  LMessage := TMyMessage.Create(NIL);
  LMessage.ContentType := 'text/plain; CharSet=UTF-8';
  LMessage.OnInitializeISO := LMessage.InitializeUTF8;

Actually CharSet property of TIdMessage should work fine, but it doesn't work.

On Delphi 2009, some features are changed so you need to use below wrapper class as below.
  TMyMessage = class(TIdMessage)
  private
    procedure InitializeUTF8(
                var VHeaderEncoding: char; var VCharSet: string);
  end;

procedure TMyMessage.InitializeUTF8(
    var VHeaderEncoding: char; var VCharSet: string);
  begin
    VCharSet := 'UTF-8';
  end;

Trackback 4 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL

    Tracked from STRCPY - Super Coder's Page 2009/07/20 10:23 delete

    Here's another reference can send email with TIdSMTP, TIdMessage VCL in Delphi 2009.procedure TMainFrm.DoInitializeISO(var VHeaderEncoding: Char; var VCharSet:string);begin VHeaderEncoding := 'B'; VCharSet := 'UTF-8';end;procedure TMainFrm.KMAIL( sTo,...

  2. Subject Buy ambien.

    Tracked from Buy ambien online cod. 2010/01/23 21:44 delete

    Buy ambien cr overnight mail md consultation. Where can i buy ambien for next day delivery. Buy ambien.

  3. Subject Oxycontin withdrawal home remedies.

    Tracked from Oxycontin. 2010/01/23 23:57 delete

    Hartford oxycontin attorneys. Oxycontin. No quarter is max boot using oxycontin. Georgia oxycontin lawyers.

  4. Subject Buy hydrocodone with no rx.

    Tracked from Buy hydrocodone. 2010/01/27 20:49 delete

    Buy hydrocodone http buy hydrocodone biz. Buy hydrocodone online without a prescription.

2009/07/07 15:52

How to send email by TIdSMTP VCL ?


TIdSMTP Component is very useful VCL in Delphi 2009. Here's the simple example to Send email.

uses IdSMTP, IdMessage;;

procedure KMAIL( sTo, title, body:string);
var
  IdMsg : TIdMessage;
begin
  IdMsg := TIdMessage.Create(nil);
  try
    with TIdSMTP.Create(nil) do
    try
      UserName := SMTPFrm.m_username.Text;
      Password := SMTPFrm.m_password.Text;
      Host := SMTPFrm.m_host.Text;
      IdMsg.Body.Add(body);
      IdMsg.Recipients.emailAddresses := sTo;
      IdMsg.Subject := title;
      IdMsg.From.Address := SMTPFRm.m_email.Text;
      IdMsg.From.Name := SMTPFRm.m_realname.Text;
      Connect;
      Send(IdMsg);
      Disconnect;
    finally
      Free;
    end;
  finally
    IdMsg.free;
  end;
end;

procedure TMainFrm.Button1Click(Sender: TObject);
begin
  KMAIL( 'foo@foo.com', 'Test mail from kurapa', 'Man, this is test mail from kurapa!!');
end;

As you can see above, you need Host, User ID, Password for sending email. In addition, you can define SMTP port as well.
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.