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.
This commit is contained in:
Winni Neessen 2024-10-23 13:10:13 +02:00
parent ab835b7870
commit 1c8b2904f5
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -242,6 +242,9 @@ var (
// provided as argument to the WithDSN Option. // provided as argument to the WithDSN Option.
ErrInvalidDSNRcptNotifyCombination = errors.New("DSN rcpt notify option NEVER cannot be " + ErrInvalidDSNRcptNotifyCombination = errors.New("DSN rcpt notify option NEVER cannot be " +
"combined with any of SUCCESS, FAILURE or DELAY") "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. // 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. // - An Option function that sets the custom SMTP authentication for the Client.
func WithSMTPAuthCustom(smtpAuth smtp.Auth) Option { func WithSMTPAuthCustom(smtpAuth smtp.Auth) Option {
return func(c *Client) error { return func(c *Client) error {
if smtpAuth == nil {
return ErrSMTPAuthMethodIsNil
}
c.smtpAuth = smtpAuth c.smtpAuth = smtpAuth
c.smtpAuthType = SMTPAuthCustom c.smtpAuthType = SMTPAuthCustom
return nil return nil