Skip to content

Commit

Permalink
Refactor Connect() func
Browse files Browse the repository at this point in the history
  • Loading branch information
xhit committed Apr 11, 2020
1 parent eb590b3 commit 9f4ee37
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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{
Expand Down

0 comments on commit 9f4ee37

Please sign in to comment.