1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| // This code supports using TLS/SSL encryption; if sending to port 25 it uses plain-text SMTP.
uses
..., smtpsend,ssl_openssl; //probably other ssl units can be used, too.
// MailData is the text of the mail.
function SendMail(
User, Password,
MailFrom, MailTo,
SMTPHost, SMTPPort: string;
MailData: string): Boolean;
var
SMTP: TSMTPSend;
sl:TStringList;
begin
Result:=False;
SMTP:=TSMTPSend.Create;
sl:=TStringList.Create;
try
sl.text:=Maildata;
SMTP.UserName:=User;
SMTP.Password:=Password;
SMTP.TargetHost:=SMTPHost;
SMTP.TargetPort:=SMTPPort;
SMTP.AutoTLS:=true;
if Trim(SMTPPort)<>'25' then
SMTP.FullSSL:=true; // if sending to port 25, don't use encryption
if SMTP.Login then
begin
result:=SMTP.MailFrom(MailFrom, Length(MailData)) and
SMTP.MailTo(MailTo) and
SMTP.MailData(sl);
SMTP.Logout;
end;
finally
SMTP.Free;
sl.Free;
end;
end; |
Partager