Delphi 使用 SMTP 发送电子邮件时出现连接超时错误?
如何使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到的错误意味着此行上的连接失败:
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?