问题
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