Search results for 'TIdMessage'. 3 post(s) found.
2009/07/20 10:22
How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
2009/07/20 10:22 in Delphi

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;
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.
Another posts included in "Delphi"
| When subject is crashing in TIdSMTP VCL (0) | 2009/07/20 |
| Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (0) | 2009/07/20 |
| How to get file created time, modified time, and last accessed time ? (0) | 2009/08/19 |
| How to encode subject content when sending mail with TIdMessage ? (0) | 2009/07/16 |
| Base64 Encoding/Decoding function for Delphi (0) | 2009/07/16 |
| How to send email by TIdSMTP VCL ? (0) | 2009/07/07 |
| How to return exit code such as exit() function in C/C++ ? (0) | 2009/07/02 |
| How to get parameter string ? (0) | 2009/06/30 |
Trackback : Cannot send a trackbact to this post.
2009/07/16 16:35
How to encode subject content when sending mail with TIdMessage ?
2009/07/16 16:35 in Delphi

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;
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;
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;
private
procedure InitializeUTF8(
var VHeaderEncoding: char; var VCharSet: string);
end;
procedure TMyMessage.InitializeUTF8(
var VHeaderEncoding: char; var VCharSet: string);
begin
VCharSet := 'UTF-8';
end;
Another posts included in "Delphi"
| How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL (0) | 2009/07/20 |
| When subject is crashing in TIdSMTP VCL (0) | 2009/07/20 |
| Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ... (0) | 2009/07/20 |
| Base64 Encoding/Decoding function for Delphi (0) | 2009/07/16 |
| How to send email by TIdSMTP VCL ? (0) | 2009/07/07 |
| How to return exit code such as exit() function in C/C++ ? (0) | 2009/07/02 |
| How to get parameter string ? (0) | 2009/06/30 |
| Save TBitmap image to Jpeg format image in Delphi (0) | 2009/06/26 |
Trackback : Cannot send a trackbact to this post.
-
Subject How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
2009/07/20 10:23
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,...
-
Subject Buy ambien.
2010/01/23 21:44
Buy ambien cr overnight mail md consultation. Where can i buy ambien for next day delivery. Buy ambien.
-
Subject Oxycontin withdrawal home remedies.
2010/01/23 23:57
Hartford oxycontin attorneys. Oxycontin. No quarter is max boot using oxycontin. Georgia oxycontin lawyers.
-
Subject Buy hydrocodone with no rx.
2010/01/27 20:49
Buy hydrocodone http buy hydrocodone biz. Buy hydrocodone online without a prescription.
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;
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.
Another posts included in "Delphi"
| Base64 Encoding/Decoding function for Delphi (0) | 2009/07/16 |
| How to encode subject content when sending mail with TIdMessage ? (0) | 2009/07/16 |
| How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL (0) | 2009/07/20 |
| How to return exit code such as exit() function in C/C++ ? (0) | 2009/07/02 |
| How to get parameter string ? (0) | 2009/06/30 |
| Save TBitmap image to Jpeg format image in Delphi (0) | 2009/06/26 |
| How to get screen resolution in case of using multiple monitors ? (0) | 2008/12/16 |
| How to turn off monitor ? (0) | 2008/12/10 |
Prev

Rss Feed