应该不会吧.我用的是D7,INDY9.在线程里发邮件,从未出现你所说的问题.
我的代码如下,供你参考:
procedure TMailThread.Execute;
var IdSMTP:TIdSMTP;
IdMsg:TIdmessage;
Stop:boolean;
begin
{ Place thread code here }
FreeOnTerminate := True;
synchronize(LoadFromMain); //取邮件主题内容等
Idsmtp:=TIdsmtp.Create(nil);
IdMsg:=TIdmessage.Create(nil);
try
//构造邮件体
IdMsg.Subject := FSubject;
IdMsg.Body.Text := FContent;
IdMsg.From.Address := FMail;
IdMsg.Recipients.EMailAddresses := GetEmail(FToMail);
if FileExists(FAttachment) then TIdAttachment.Create(IdMsg.MessageParts, FAttachment);
//填充SMTP
IdSMTP.Host := GetHost;
IdSMTP.Port := 25;
IdSMTP.Username := GetUsername;
IdSMTP.Password := GetPS;
//连接到SMTP服务器
try
IdSMTP.Connect;
except
SendForm.Sending := false; //更改主窗口变量
exit;
end;
//验证身分
if (IdSMTP.AuthSchemesSupported.IndexOf('LOGIN')<>-1) then
begin
IdSMTP.AuthenticationType :=atLogin;
try
if not IdSMTP.Authenticate then //未通过验证
begin
SendForm.Sending := false;
if IdSMTP.Connected then IdSMTP.Disconnect;
exit;
end;
except
SendForm.Sending := false;
if IdSMTP.Connected then IdSMTP.Disconnect;
exit;
end;
end;
//发送信件
try
IdSMTP.Send(IdMsg);
synchronize(DoSendLogTrue); //发送成功,执行DoSendLogTrue函数
except
SendForm.Sending := false;
synchronize(DoSendLogFalse); //发送失败,执行DoSendLogFalse函数
if IdSMTP.Connected then IdSMTP.Disconnect;
end;
SendForm.Sending := false;
if IdSMTP.Connected then IdSMTP.Disconnect;
finally
IdSMTP.Free;
IdMsg.Free;
end;
end;