Skip to content

Commit

Permalink
Update Mail4Delphi.pas
Browse files Browse the repository at this point in the history
  • Loading branch information
juliosenha committed Feb 18, 2021
1 parent 939705a commit be2f109
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Mail4Delphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ destructor TMail.Destroy;

function TMail.Disconnect: Boolean;
begin
FIdSMTP.Disconnect;
if FIdSMTP.Connected then
FIdSMTP.Disconnect;
UnLoadOpenSSLLibrary;
Result := True;
end;
Expand All @@ -326,11 +327,13 @@ class function TMail.New: IMail;
end;

function TMail.SendMail: Boolean;
var
LImplicitConnection: Boolean;
begin
if not SetUpEmail then
raise Exception.Create('Incomplete data!');
if not FIdSMTP.Connected then
Self.Connect;
LImplicitConnection := Self.Connect;
try
try
FIdSMTP.Send(FIdMessage);
Expand All @@ -340,7 +343,7 @@ function TMail.SendMail: Boolean;
raise Exception.Create('Error sending message: ' + E.Message);
end;
finally
if FIdSMTP.Connected then
if LImplicitConnection then
Self.Disconnect;
end;
end;
Expand Down

0 comments on commit be2f109

Please sign in to comment.