Search code examples
asp.netasp.net-mvcasp.net-mvc-5actionmaileractionmailer.net

ActionMailer.net/ActionMailerNext - how to confirm if an eMail has even been sent?


Working with ActionMailerNext, which is a fork of the now-dead ActionMailer.net, and I cannot for the life of me figure out how to determine if the eMail has been sent, or if an error occurred that prevented the eMail from being sent.

Neither site provides any idea on how to do this. Two hours of Googling has been similarly productive (NOT!).

Typically, with something like a database update, I can do a

if((await _db.SaveChangesAsync()) > 0){ ... }

and be able to fork the code between yes-it-updated and no-it-failed portions. I need to be able to do this with ActionMailerNext, and I haven’t a clue how.

The actual .Deliver() returns a

System.Collections.Generic.IList<ActionMailerNext.Interfaces.IMailResponse>

But I have no clue how to unpack it because I have no idea what is inside it. Any attempt to google IMailResponse does not bring me back anything of use.


EDIT:

For those who would like to know, the returned collection contains two variables: a string Email and an Enum called DeliveryStatus that provides one of four responses for each eMail sent: DELIVERED, INVALID, QUEUED and REJECTED. By doing the following, even if only one eMail was sent (because my needs are simple):

if(e.All(x => x.DeliveryStatus == DeliveryStatus.DELIVERED)) {
  // Do if ALL eMails were sent
} else {
  // Fallback if ANY eMail was not sent
}

I was able to ensure that a fallback existed if one or more eMails failed to get sent.

Keep in mind, though: this only is for eMails getting delivered to the outgoing SMTP server; the system has no clue what happens beyond that.

Thanks to @ADyson below for the poke needed for my sleep-deprived brain to function correctly.


Solution

  • For those who would like to know, the returned collection contains two variables: a string Email and an Enum called DeliveryStatus that provides one of four responses for each eMail sent: DELIVERED, INVALID, QUEUED and REJECTED. By doing the following, even if only one eMail was sent (because my needs are simple):

    if(e.All(x => x.DeliveryStatus == DeliveryStatus.DELIVERED)) {
      // Do if ALL eMails were sent
    } else {
      // Fallback if ANY eMail was not sent
    }
    

    I was able to ensure that a fallback existed if one or more eMails failed to get sent.

    Keep in mind, though: this only is for eMails getting delivered to the outgoing SMTP server; the system has no clue what happens beyond that.

    Thanks to @ADyson for the poke needed for my sleep-deprived brain to function correctly.