通过将答案放在一起,您可以获得以下代码。不要忘记将和库例如从您Nathanial Woolls
的项目文件夹或从.here
libeay32.dll
ssleay32.dll
here
following places
uses
IdMessage, IdSMTP, IdSSLOpenSSL, IdGlobal, IdExplicitTLSClientServerBase;
procedure SendEmail(const Recipients: string; const Subject: string; const Body: string);
var
SMTP: TIdSMTP;
Email: TIdMessage;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
SMTP := TIdSMTP.Create(nil);
Email := TIdMessage.Create(nil);
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
try
SSLHandler.MaxLineAction := maException;
SSLHandler.SSLOptions.Method := sslvTLSv1;
SSLHandler.SSLOptions.Mode := sslmUnassigned;
SSLHandler.SSLOptions.VerifyMode := [];
SSLHandler.SSLOptions.VerifyDepth := 0;
SMTP.IOHandler := SSLHandler;
SMTP.Host := 'smtp.gmail.com';
SMTP.Port := 587;
SMTP.Username := 'yourusername@gmail.com';
SMTP.Password := 'yourpassword';
SMTP.UseTLS := utUseExplicitTLS;
Email.From.Address := 'yourusername@gmail.com';
Email.Recipients.EmailAddresses := Recipients;
Email.Subject := Subject;
Email.Body.Text := Body;
SMTP.Connect;
SMTP.Send(Email);
SMTP.Disconnect;
finally
SMTP.Free;
Email.Free;
SSLHandler.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SendEmail('recipient@whatever.com', 'Subject', 'Body');
end;
希望这有帮助