如何在Delphi 2010中发送电子邮件,例如(验证电子邮件、丢失密码或任何HTML/纯文本电子邮件)。
我尝试使用以下代码发送邮件,但在发送邮件时出现“Socket Error #10060 Connection Timed Out”的EIdSocket错误。
我尝试使用以下代码发送邮件,但在发送邮件时出现“Socket Error #10060 Connection Timed Out”的EIdSocket错误。
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;