Skip to content

Commit e6e58c5

Browse files
committed
Update SendEmail.pas
1 parent 6a7d2d8 commit e6e58c5

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

src/SendEmail.pas

+23-23
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ TSendEmail = class
3434
class var RW: TMultiReadExclusiveWriteSynchronizer;
3535
class var FInstance: TSendEmail;
3636

37-
function IsConnected: Boolean;
3837
procedure Reconnect(AResend: Boolean = False);
3938

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

7272
function OnLog(const AExecute: TProc<string>; const ALogMode: TLogMode = lmComponent): TSendEmail;
7373
function OnWorkBegin(const AExecute: TProc<Int64>): TSendEmail;
@@ -701,6 +701,28 @@ function TSendEmail.Disconnect: TSendEmail;
701701
end;
702702
end;
703703

704+
function TSendEmail.IsConnected: Boolean;
705+
begin
706+
Result := False;
707+
708+
try
709+
Result := FIdSMTP.Connected;
710+
except
711+
on E: Exception do
712+
begin
713+
if E.Message.ToUpper.Contains('CLOSING CONNECTION') or
714+
E.Message.ToUpper.Contains('SSL3_GET_RECORD')
715+
then
716+
try
717+
Reconnect(False);
718+
Result := True;
719+
except
720+
Exit;
721+
end;
722+
end;
723+
end;
724+
end;
725+
704726
function TSendEmail.OnLog(const AExecute: TProc<string>; const ALogMode: TLogMode = lmComponent): TSendEmail;
705727
begin
706728
Result := Self;
@@ -727,28 +749,6 @@ function TSendEmail.OnWorkEnd(const AExecute: TProc): TSendEmail;
727749
FWorkEnd := AExecute;
728750
end;
729751

730-
function TSendEmail.IsConnected: Boolean;
731-
begin
732-
Result := False;
733-
734-
try
735-
Result := FIdSMTP.Connected;
736-
except
737-
on E: Exception do
738-
begin
739-
if E.Message.ToUpper.Contains('CLOSING CONNECTION') or
740-
E.Message.ToUpper.Contains('SSL3_GET_RECORD')
741-
then
742-
try
743-
Reconnect(False);
744-
Result := True;
745-
except
746-
Exit;
747-
end;
748-
end;
749-
end;
750-
end;
751-
752752
procedure TSendEmail.Reconnect(AResend: Boolean = False);
753753
begin
754754
if AResend then

0 commit comments

Comments
 (0)