使用SMTP与Delphi发送电子邮件时连接超时错误?

Raf*_*ari 5 delphi delphi-2010

如何使用delphi 2010发送电子邮件地址,例如(verefication email,密码丢失或任何html /纯文本电子邮件.

我尝试使用以下代码,但我EIdSocket Eroor with message 'Socket Error #10060 Connection Timed Out'在尝试发送邮件时得到.

procedure TForm5.btnSendMailClick(Sender: TObject);
begin

//setup SMTP
smtppass := ed_IdVerification.Text;
SMTP.Host := 'smtp.google.com';   // Controle a distance
SMTP.Port := 465;
smtp.Username := 'hetallica69@gmail.com';
smtp.Password := QuotedStr(smtppass);


//setup mail message

MailMessage.From.Address := 'hetallica69@gmail.com';
MailMessage.Recipients.EMailAddresses := '_rafik@live.fr';

MailMessage.Subject := 'Confirm your account';
MailMessage.Body.Text := 'Text goes here';

//send mail
try
 try
   if not smtp.Connected then SMTP.Connect() ;
   SMTP.Send(MailMessage) ;
 except on E:Exception do
   ShowMessage(E.Message);
 end;
   finally
     if SMTP.Connected then SMTP.Disconnect;
   end;
end;
Run Code Online (Sandbox Code Playgroud)

Mar*_*ams 5

您收到的错误意味着此行上的连接失败:SMTP.Connect()

通常,这意味着端口错误、服务器未启动或您没有连接。

在这种情况下,您没有连接,很可能是因为您的 ISP 阻止了与该远程端口的连接。

尝试从您的托管 Web 服务器发送电子邮件。

即使您可以连接,您的代码也无法按原样运行。Google SMTP 服务器上的端口 465 需要安全 (SSL) 连接。你仍然需要实现它。看一看:如何使用 Gmail 的 SMTP 和 Indy 10 发送电子邮件?

  • 这是错误的。它失败了,因为 gmail 使用安全连接,而海报没有。它与连接性或服务器状态无关。(gmail 没有经常关闭的习惯。)阅读原始问题的评论,并按照其中提供的链接之一进行操作。:) 您可能想在投票开始之前删除此答案。注意:我不是在投票。 (2认同)