From 1c8b2904f50bd0296630cf0c1440e35aa31706b6 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Wed, 23 Oct 2024 13:10:13 +0200 Subject: [PATCH] Add error check for nil SMTP authentication method Ensure that the SMTP authentication method is not nil by adding a corresponding error check in the WithSMTPAuthCustom function. Introduced a new error, ErrSMTPAuthMethodIsNil, to handle this validation. --- client.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client.go b/client.go index 3f36a94..af36b47 100644 --- a/client.go +++ b/client.go @@ -242,6 +242,9 @@ var ( // provided as argument to the WithDSN Option. ErrInvalidDSNRcptNotifyCombination = errors.New("DSN rcpt notify option NEVER cannot be " + "combined with any of SUCCESS, FAILURE or DELAY") + + // ErrSMTPAuthMethodIsNil indicates that the SMTP authentication method provided is nil + ErrSMTPAuthMethodIsNil = errors.New("SMTP auth method is nil") ) // NewClient creates a new Client instance with the provided host and optional configuration Option functions. @@ -510,6 +513,9 @@ func WithSMTPAuth(authtype SMTPAuthType) Option { // - An Option function that sets the custom SMTP authentication for the Client. func WithSMTPAuthCustom(smtpAuth smtp.Auth) Option { return func(c *Client) error { + if smtpAuth == nil { + return ErrSMTPAuthMethodIsNil + } c.smtpAuth = smtpAuth c.smtpAuthType = SMTPAuthCustom return nil