Skip to content

Commit

Permalink
[MINT-2637] Handle sending email with no recipients (#1283)
Browse files Browse the repository at this point in the history
* Modify GoSimpleMailService's SendEmail to sendEmail since it's only ever used by the GoSimpleMailService.Send() method

* Added check in GoSimpleMailService.sendEmail() to check the recipient list before sending
  • Loading branch information
ClayBenson94 authored Aug 6, 2024
1 parent af32c56 commit 4acbe5b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/shared/oddmail/go_simple_mail_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,23 @@ func (g GoSimpleMailService) Send(
return err
}

return g.SendEmail(email)
return g.sendEmail(email)
}

// SendEmail is a GoSimpleMail specific method allowing for dispatching an email using a mail.Email object
func (g GoSimpleMailService) SendEmail(email *mail.Email) error {
// sendEmail is a GoSimpleMail specific method allowing for dispatching an email using a mail.Email object
func (g GoSimpleMailService) sendEmail(email *mail.Email) error {
if !g.config.GetEnabled() {
return nil
}

// Before we send the email, we need to check to see if it actually has any recipients and return early if not
// This is because the go-simple-mail actually returns an error if there are no recipients, but we don't want to treat that as an error
// and would rather just return early when this happens
// TODO: It would be nice to have access to a logger/context here so we could logger.Warn() in this case
if len(email.GetRecipients()) == 0 {
return nil
}

smtpClient, err := g.smtpServer.Connect()
if err != nil {
return err
Expand Down

0 comments on commit 4acbe5b

Please sign in to comment.