Skip to content

Using System.Net.Mail.MailMessage

JP Toto edited this page Nov 19, 2013 · 6 revisions

You can also use System.Net.Mail.MailMessage to compose message objects to send through Postmark.

string to = "Some User <someone@example.com>";
string from = "Another User <someone_else@example.com>";
var mailMessage = new System.Net.MailMailMessage(from, to);
mailMessage.Subject = "Sending with Dotnet!";
mailMessage.Body = "Test Message";

The PostmarkMessage class accepts a MailMessage object as a constructor parameter:

var postmarkMessage = new PostmarkMessage(mailMessage);

We'll need a PostmarkClient object in order to send our message.

var newClient = new PostmarkClient("server_token");

Now we're ready to send our message.

var response = newClient.SendMessage(postmarkMessage);

Clone this wiki locally