Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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;
like image 708
Rafik Bari Avatar asked Dec 20 '11 13:12

Rafik Bari


People also ask

Why is SMTP timing out?

If you get a 'Connection Timed out' error when sending email via our SMTP relay, it means that you are using an smtp port that is blocked. By default, we recommend using port 25 when sending emails via our SMTP relay. However, some ISPs may block port 25.

Can't connect to connection timed out?

The error indicates that the server didn't respond to the client and the client program gave up (timed out). The following are common causes for this error: The security group or network ACL doesn't allow access. There is a firewall on the instance's operating system.


1 Answers

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?

like image 148
Marcus Adams Avatar answered Oct 06 '22 01:10

Marcus Adams