Skip to content

Commit

Permalink
Merge pull request #12 from mateusvicente100/master
Browse files Browse the repository at this point in the history
Add Timemout Property
  • Loading branch information
juliosenha authored Jun 23, 2021
2 parents a28dbb4 + 77f8757 commit cfff5fe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/Mail4Delphi.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface

uses
{$IF DEFINED(FPC)}
Classes;
Classes;
{$ELSE}
System.Classes;
{$ENDIF}
Expand All @@ -31,6 +31,8 @@ interface
function Auth(const AValue: Boolean): IMail;
function SSL(const AValue: Boolean): IMail;
function ContentType(const AValue: string): IMail;
function ConnectTimeout(const ATimeout: Integer): IMail;
function ReadTimeout(const ATimeout: Integer): IMail;
function Clear: IMail;
function SendMail: Boolean;
function SetUpEmail: Boolean;
Expand Down
26 changes: 21 additions & 5 deletions src/Mail4Delphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ interface

uses
{$IF DEFINED(FPC)}
Classes, SysUtils, Variants,
Classes, SysUtils, Variants,
{$ELSE}
System.Classes, System.SysUtils, System.Variants,
System.Classes, System.SysUtils, System.Variants,
{$ENDIF}
IdSMTP, IdSSLOpenSSL, IdMessage, IdMessageParts, IdText, IdAttachmentFile, IdExplicitTLSClientServerBase, Mail4Delphi.Intf;

Expand All @@ -19,8 +19,8 @@ interface

TMail = class(TInterfacedObject, IMail)
private const
CONNECT_TIMEOUT = 10000;
READ_TIMEOUT = 10000;
CONNECT_TIMEOUT = 60000;
READ_TIMEOUT = 60000;
private
FIdSSLIOHandlerSocket: TIdSSLIOHandlerSocketOpenSSL;
FIdSMTP: TIdSMTP;
Expand Down Expand Up @@ -48,6 +48,8 @@ TMail = class(TInterfacedObject, IMail)
function Auth(const AValue: Boolean): IMail;
function SSL(const AValue: Boolean): IMail;
function ContentType(const AValue: string): IMail;
function ConnectTimeout(const ATimeout: Integer): IMail;
function ReadTimeout(const ATimeout: Integer): IMail;
function Clear: IMail;
function SendMail: Boolean;
function SetUpEmail: Boolean;
Expand Down Expand Up @@ -162,6 +164,13 @@ function TMail.Port(const APort: Integer): IMail;
Result := Self;
end;

function TMail.ReadTimeout(const ATimeout: Integer): IMail;
begin
if (ATimeout > 0) then
FIdSMTP.ReadTimeout := ATimeout;
Result := Self;
end;

function TMail.ReceiptRecipient(const AValue: Boolean): IMail;
begin
FReceiptRecipient := AValue;
Expand Down Expand Up @@ -249,7 +258,7 @@ function TMail.Connect: Boolean;
begin
FIdSSLIOHandlerSocket.SSLOptions.Method := sslvTLSv1_2;
FIdSSLIOHandlerSocket.SSLOptions.Mode := sslmUnassigned;
FIdSMTP.IOHandler := IdSSLIOHandlerSocket;
FIdSMTP.IOHandler := FIdSSLIOHandlerSocket;
FIdSMTP.UseTLS := utUseExplicitTLS;
if FSSL then
begin
Expand Down Expand Up @@ -279,6 +288,13 @@ function TMail.Connect: Boolean;
end;
end;

function TMail.ConnectTimeout(const ATimeout: Integer): IMail;
begin
if (ATimeout > 0) then
FIdSMTP.ConnectTimeout := ATimeout;
Result := Self;
end;

function TMail.ContentType(const AValue: string): IMail;
begin
FIdText.ContentType := AValue;
Expand Down

0 comments on commit cfff5fe

Please sign in to comment.