From e6e58c52e083a1d02148a3368d60938b65ac1300 Mon Sep 17 00:00:00 2001 From: Danilo Lucas Date: Wed, 14 Jul 2021 17:26:36 -0300 Subject: [PATCH] Update SendEmail.pas --- src/SendEmail.pas | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/SendEmail.pas b/src/SendEmail.pas index 5dfcf90..b630b14 100644 --- a/src/SendEmail.pas +++ b/src/SendEmail.pas @@ -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); @@ -68,6 +67,7 @@ TSendEmail = class function Send(const ADisconnectAfterSending: Boolean = True): TSendEmail; function SendAsync(const ACallBack: TProc = nil; const ADisconnectAfterSending: Boolean = True): TSendEmail; function Disconnect: TSendEmail; + function IsConnected: Boolean; function OnLog(const AExecute: TProc; const ALogMode: TLogMode = lmComponent): TSendEmail; function OnWorkBegin(const AExecute: TProc): TSendEmail; @@ -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; const ALogMode: TLogMode = lmComponent): TSendEmail; begin Result := Self; @@ -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