Fix(close): Access to nil variable causes panic

This commit is contained in:
Alysson Ribeiro 2024-11-06 10:20:59 +01:00 committed by GitHub
parent 9ca7d24f6a
commit 8c4eb62360
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:
// - An error if the disconnection fails; otherwise, returns nil.
func (c *Client) Close() error {
if !c.smtpClient.HasConnection() {
if c.smtpClient == nil || !c.smtpClient.HasConnection() {
return nil
}
if err := c.smtpClient.Quit(); err != nil {