我無法發送使用TIdSMTP
我收到以下消息的電子郵件:Socket Error # 10060/Connection timed out.
sendmail將以TIdSMTP連接超時
我使用的版本的Delphi XE6
這裏是我的代碼:
procedure TForm1.Button1Click(Sender: TObject);
var
IdSMTP : TIdSMTP;
IdMessage : TIdMessage;
begin
IdSMTP := TIdSMTP.Create (Nil);
IdMessage := TIdMessage.Create (Nil);
IdSMTP.Host := 'mail.mysmtp.com';
IdSMTP.Port := 25;
IdSMTP.Connect();
IdMessage.From.Address := '[email protected]';
IdMessage.From.Name := 'Contato';
IdMessage.Recipients.EMailAddresses := '[email protected]';
IdMessage.Subject := 'Contato test';
IdMessage.Body.Text := 'test';
IdSMTP.Send (IdMessage);
IdSMTP.Disconnect();
FreeAndNil (IdMessage);
FreeAndNil (IdSMTP);
end;
IdSMTP.connect引發異常嗎?你能通過Telnet連接到你的SMTP服務器嗎? – 2014-11-08 15:33:05
你確定主機?也許無關,但一些身份驗證也會丟失(SMTP/SMTP之前的用戶名/密碼/ POP),端口,TSL ...看看[這裏](http://stackoverflow.com/a/11157460/1699210),也許你會必須改進你的問題。 – bummi 2014-11-08 15:53:22
請注意,您可以簡單地在沒有(nil)的情況下編寫'TIdSMTP.Create'和'TIdMessage.Create'。也可以使用try .. finally,並將finally/FreeAndNil放在finally塊中以消除內存泄漏的風險。 – mjn 2014-11-08 16:08:58