mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +01:00
Fix Quit handling when initial HELO fails
Ensure QUIT command can be sent even if initial HELO fails. Added a check to skip retrying HELO if it already failed, allowing for proper closing of the connection. This prevents potential hangs or errors during connection termination.
This commit is contained in:
parent
572751ac10
commit
74fa3f6f62
1 changed files with 13 additions and 2 deletions
15
smtp/smtp.go
15
smtp/smtp.go
|
@ -554,8 +554,19 @@ func (c *Client) Noop() error {
|
||||||
|
|
||||||
// Quit sends the QUIT command and closes the connection to the server.
|
// Quit sends the QUIT command and closes the connection to the server.
|
||||||
func (c *Client) Quit() error {
|
func (c *Client) Quit() error {
|
||||||
if err := c.hello(); err != nil {
|
// If we did already tried to send a EHLO/HELO but it failed, we still need to be able to send
|
||||||
return err
|
// 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")
|
_, _, err := c.cmd(221, "QUIT")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue