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

发布于 2024-12-22 06:15:04 字数 1257 浏览 1 评论 0原文

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

我尝试使用以下代码,但收到 EIdSocket Eroor 并显示消息“套接字错误 #10060 连接超时” ' 尝试发送邮件时。

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 := '[email protected]';
smtp.Password := QuotedStr(smtppass);


//setup mail message

MailMessage.From.Address := '[email protected]';
MailMessage.Recipients.EMailAddresses := '[email protected]';

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;

how to send an email address with delphi 2010 such as ( verefication email, password lost, or any html/plain text emails.

i tried with the following code but i get EIdSocket Eroor with message 'Socket Error #10060 Connection Timed Out' when trying to send the mail.

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 := '[email protected]';
smtp.Password := QuotedStr(smtppass);


//setup mail message

MailMessage.From.Address := '[email protected]';
MailMessage.Recipients.EMailAddresses := '[email protected]';

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁人与我共长歌 2024-12-29 06:15:04

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

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

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

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

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

The error that you are receiving means that the connection is failing on this line: SMTP.Connect().

Usually, it means the port is wrong, the server is not up, or you don't have connectivity.

In this case, you don't have connectivity, most likely because your ISP is blocking connection to that remote port.

Try sending the email from your hosted web server.

Even if you could connect, your code won't work as is. Port 465 on Google's SMTP server requires a secure (SSL) connection. You'll still need to implement that. Take a look at: How do I send e-mail using Gmail's SMTP and Indy 10?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文