我是说我解决了乱码问题.
发信我是一直成功的.代码如下,专门测试用的一个线程:
unit testUnit;
interface
uses
Classes, SysUtils, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdMessageClient, IdSMTP;
type
Ttest = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure Ttest.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }
{ Ttest }
procedure Ttest.Execute;
var IdSMTP:TIdSMTP;
IdMsg:TIdmessage;
begin
{ Place thread code here }
FreeOnTerminate := True;
Idsmtp:=TIdsmtp.Create(nil);
IdMsg:=TIdmessage.Create(nil);
try
//构造邮件体
IdMsg.Subject := 'testhtmlmail';
idMsg.ContentType := 'text/html';
IdMsg.Body.LoadFromFile('c:/test2.htm');
IdMsg.From.Address := 'oldice@tom.com';
IdMsg.Recipients.EMailAddresses := 'iseekwhatiseek@hotmail.com';
//填充SMTP
IdSMTP.Host := 'smtp.tom.com';
IdSMTP.Port := 25;
IdSMTP.Username := 'oldice';
IdSMTP.Password := ********;
//连接到SMTP服务器
try
IdSMTP.Connect;
except
exit;
end;
//验证身分
if (IdSMTP.AuthSchemesSupported.IndexOf('LOGIN')<>-1) then
begin
IdSMTP.AuthenticationType :=atLogin;
try
if not IdSMTP.Authenticate then //未通过验证
begin
if IdSMTP.Connected then IdSMTP.Disconnect;
exit;
end;
except
if IdSMTP.Connected then IdSMTP.Disconnect;
exit;
end;
end;
//发送信件
try
IdSMTP.Send(IdMsg);
except
if IdSMTP.Connected then IdSMTP.Disconnect;
end;
if IdSMTP.Connected then IdSMTP.Disconnect;
finally
IdSMTP.Free;
IdMsg.Free;
end;
end;
end.