diff --git a/smtp/smtp.go b/smtp/smtp.go index 77b5fb0..208677f 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -554,8 +554,19 @@ func (c *Client) Noop() error { // Quit sends the QUIT command and closes the connection to the server. func (c *Client) Quit() error { - if err := c.hello(); err != nil { - return err + // If we did already tried to send a EHLO/HELO but it failed, we still need to be able to send + // a QUIT to close the connection. + // c.hello() will return the global helloErr of the Client, which will always be set if the HELO + // failed before. Therefore if we already sent a HELO and the error is not nil, we skip another + // EHLO/HELO try + c.mutex.RLock() + didHello := c.didHello + helloErr := c.helloError + c.mutex.RUnlock() + if !didHello || helloErr == nil { + if err := c.hello(); err != nil { + return err + } } _, _, err := c.cmd(221, "QUIT") if err != nil {