Connection timed out error when using SMTP to send emails with Delphi?

人盡茶涼 提交于 2019-12-04 23:49:32

问题


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 := '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;

回答1:


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?



来源:https://stackoverflow.com/questions/8576451/connection-timed-out-error-when-using-smtp-to-send-emails-with-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!