function TdMail.SendMail(Recipients, Body: TStrings; Subject:
string): Boolean;
var
CurrentMessage: TIdMessage;
function FillMessageRecipients(RecipientsList: TStrings): Boolean;
var
I: Integer;
Item: TIdEMailAddressItem;
begin
Result:= (RecipientsList.Count > 0);
for I := 0
to RecipientsList.Count - 1
do
begin
Item:= CurrentMessage.Recipients.Add;
Item.Address:= RecipientsList[I];
end;
end;
begin
Result:= False;
CurrentMessage:= TIdMessage.Create(
nil);
try
if FillMessageRecipients(Recipients)
then
begin
CurrentMessage.From.Address:= FFromAddress;
CurrentMessage.Subject:= Subject;
CurrentMessage.Body.AddStrings(Body);
Smtp.Password:= TdTools.DecryptPassword(FPasswordEncrypted);
try
Smtp.Connect;
Smtp.Send(CurrentMessage);
Smtp.Disconnect;
if Assigned(FOnMailSend)
then
begin
FOnMailSend(Self, CurrentMessage.Recipients[0].Address, CurrentMessage.Subject);
end;
Result:= True;
except
on E:
Exception do
begin
if Assigned(FOnMailError)
then
begin
FOnMailError(Self, CurrentMessage.Recipients[0].Address, CurrentMessage.Subject, conTextMailSendError + E.
Message);
end;
end;
end;
end;
finally
CurrentMessage.Free;
// <- bei dieser Freigabe
end;
end;