How to send an email using Postmark in a C# application

Postmark is a service that ensures the email you send from your application reaches your recipient and not its Spam folder (which will likely happen if you use your own SMTP server or Google’s one).

Postmark gives you 1000 emails for free, which allows you to give a try risk-free.

So how do you send an email with PostMark?

First you will need to create an account at Postmark. It will take you 10 minutes to enter your information and to click in the link in your emails.

Then you will need to add some records in your DNS, Postmark explains the steps very well (5 minutes).

Once your account is correctly set up, copy the ApiKey they give you, you will need it in your application.

Then you will need to download Postmark.net from Git. It is an assembly that handles the plumbing to the Postmark API for you.

Note: Add the assembly as a reference (don’t forget to unblock the zip before extracting the dll)

Use the following code to send an email:

var postmark = new PostmarkClient(ConfigurationManager.AppSettings["PostMark.ApiKey"]); var message = new PostmarkMessage { To = email, From = ConfigurationManager.AppSettings["PostMark.From"], // This must be a verified sender signature Subject = subject, TextBody = plain, HtmlBody = html }; var response = postmark.SendMessage(message);

Remarks

1. I advice you to send the email asynchronously to not be dependent on Postmark availability and responsiveness and to log any error.

2. Postmark can notify your application if an email bounces. This is a neat feature.

3. The From email address must be the email address you have verified in Postmark.

Voila!