Merge pull request #353 from sonalys/fix/close_panic

Fix(close): Access to nil variable causes panic
This commit is contained in:
Winni Neessen 2024-11-06 10:51:53 +01:00 committed by GitHub
commit 632ac17845
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -996,7 +996,7 @@ func (c *Client) DialWithContext(dialCtx context.Context) error {
// Returns: // Returns:
// - An error if the disconnection fails; otherwise, returns nil. // - An error if the disconnection fails; otherwise, returns nil.
func (c *Client) Close() error { func (c *Client) Close() error {
if !c.smtpClient.HasConnection() { if c.smtpClient == nil || !c.smtpClient.HasConnection() {
return nil return nil
} }
if err := c.smtpClient.Quit(); err != nil { if err := c.smtpClient.Quit(); err != nil {