Skip to content

Commit

Permalink
Add error check for nil SMTP authentication method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wneessen committed Oct 23, 2024
1 parent ab835b7 commit 1c8b290
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c8b290

Please sign in to comment.