From 9f4ee3747eb80933e6f7f4643d412bddbd0b858b Mon Sep 17 00:00:00 2001 From: Santiago De la Cruz Date: Sat, 11 Apr 2020 16:01:59 -0400 Subject: [PATCH] Refactor Connect() func --- email.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/email.go b/email.go index fafa8a6..5217a38 100644 --- a/email.go +++ b/email.go @@ -786,15 +786,6 @@ func (server *SMTPServer) Connect() (*SMTPClient, error) { // send the result smtpConnectChannel <- err }() - } - - if server.ConnectTimeout == 0 { - // no ConnectTimeout, just fire the connect - c, err = smtpConnect(server.Host, fmt.Sprintf("%d", server.Port), a, server.Encryption, new(tls.Config)) - if err != nil { - return nil, err - } - } else { // get the connect result or timeout result, which ever happens first select { case err = <-smtpConnectChannel: @@ -804,6 +795,12 @@ func (server *SMTPServer) Connect() (*SMTPClient, error) { case <-time.After(server.ConnectTimeout): return nil, errors.New("Mail Error: SMTP Connection timed out") } + } else { + // no ConnectTimeout, just fire the connect + c, err = smtpConnect(server.Host, fmt.Sprintf("%d", server.Port), a, server.Encryption, new(tls.Config)) + if err != nil { + return nil, err + } } return &SMTPClient{