Sending emails using NServiceBus

Sending emails is a problem re-solved by developers every day. Not that it’s hard but as we all know connecting to smtp servers is known to not work super reliable at all times. To help out we created a NServiceBus satellite that gives you the benefits of the retries that comes with NServiceBus to make your email sending more robust.

The reason we wen’t for a satellite is that we can give you the robustness of a separate queue without requiring you to setup a new Endpoint or configure any message mappings.

This way every endpoint will have this capability builtin and the only config needed is the SmtpClient config section

The API for this new feature is Bus.SendEmail(new MailMessage), we’re using the System.Net.Mail.MailMessage as this is a proven abstraction for sending emails.

This entire feature was developed at the NDC2012 NServiceBus hackathon with the help of the audience so I would like to thank all the ones that showed up and helped us!

The code is currently on our develop branch and it will be included in our next major release.

A sample demonstrating all this can be found here.

Happy spamming!

This entry was posted in NServiceBus. Bookmark the permalink. Both comments and trackbacks are currently closed.
  • Daniel Marbach

    Hy andreas
    Great stuff! Udi calls this in the Andvanced Distributed course Email Gateway. I know the terminology gateway is already used. But could you somehow align the terminologies together?


    • andreasohlund

      I see what you’re getting at but the “Messaging gateway” is more of a pattern and given that we already have a “gataway for multisite operations” I don’t think we can join the 2 without confusing people. I guess you can see view a satellite as a “lightweight messaging gateway” running inprocess with your main endpoint

  • Mario Juric

    Interesting. Can it handle undelivered mail errors?

    • andreasohlund

      Not at the moment, is there a api to get at those using SmtpClient?

      • Mario Juric

        Nothing that I know much about, sorry. You will somehow have to retrieve the undelivered messages and parse them yourself. Not sure how reliably this can be done.  I haven’t research this problem very much myself. We are having a case where we might need to integrate using some mail based messaging but we previously had bad operational experiences with this, which is why an NServiceBus addition could be interesting if it has a way to handle this.