Skip to content

Commit

Permalink
Update SendEmail.pas
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Jul 14, 2021
1 parent 6a7d2d8 commit e6e58c5
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/SendEmail.pas
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ TSendEmail = class
class var RW: TMultiReadExclusiveWriteSynchronizer;
class var FInstance: TSendEmail;

function IsConnected: Boolean;
procedure Reconnect(AResend: Boolean = False);

procedure LogSMTPStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string);
Expand Down Expand Up @@ -68,6 +67,7 @@ TSendEmail = class
function Send(const ADisconnectAfterSending: Boolean = True): TSendEmail;
function SendAsync(const ACallBack: TProc<Boolean, string> = nil; const ADisconnectAfterSending: Boolean = True): TSendEmail;
function Disconnect: TSendEmail;
function IsConnected: Boolean;

function OnLog(const AExecute: TProc<string>; const ALogMode: TLogMode = lmComponent): TSendEmail;
function OnWorkBegin(const AExecute: TProc<Int64>): TSendEmail;
Expand Down Expand Up @@ -701,6 +701,28 @@ function TSendEmail.Disconnect: TSendEmail;
end;
end;

function TSendEmail.IsConnected: Boolean;
begin
Result := False;

try
Result := FIdSMTP.Connected;
except
on E: Exception do
begin
if E.Message.ToUpper.Contains('CLOSING CONNECTION') or
E.Message.ToUpper.Contains('SSL3_GET_RECORD')
then
try
Reconnect(False);
Result := True;
except
Exit;
end;
end;
end;
end;

function TSendEmail.OnLog(const AExecute: TProc<string>; const ALogMode: TLogMode = lmComponent): TSendEmail;
begin
Result := Self;
Expand All @@ -727,28 +749,6 @@ function TSendEmail.OnWorkEnd(const AExecute: TProc): TSendEmail;
FWorkEnd := AExecute;
end;

function TSendEmail.IsConnected: Boolean;
begin
Result := False;

try
Result := FIdSMTP.Connected;
except
on E: Exception do
begin
if E.Message.ToUpper.Contains('CLOSING CONNECTION') or
E.Message.ToUpper.Contains('SSL3_GET_RECORD')
then
try
Reconnect(False);
Result := True;
except
Exit;
end;
end;
end;
end;

procedure TSendEmail.Reconnect(AResend: Boolean = False);
begin
if AResend then
Expand Down

0 comments on commit e6e58c5

Please sign in to comment.