Skip to content

Using System.Net.Mail.MailMessage

Andrew Theken edited this page Dec 11, 2014 · 6 revisions

On plaforms that include the System.Net.Mail assembly, you may make use the system-provied MailMessage class to compose messages.

var to = "Some User <someone@example.com>";
var from = "Another User <someone_else@example.com>";

var mailMessage = new System.Net.Mail.MailMessage(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);

After you have acquired the postmarkMessage object, you may send it using the PostmarkClient as described on the Sending-text-and-html-emails wiki article.

Note: In the 2.x library, you can send a MailMessage using the PostmarkClient without first converting it to a PostmarkMessage.

Clone this wiki locally