Skip to content

Sending text and html email messages

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

Sending a plain text message:

First, let's create our PostmarkMessage object:

var message = new PostmarkMessage();

We can now add recipients to the To, CC, and BCC fields as needed.

message.To = "someone@someplace.com";
message.Cc = "someoneelse@someplace.com";
message.Subject = "A fun test email!";
message.TextBody = "Some plain text";
message.From = "you@yourdomain.com";

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

var client = new PostmarkClient("server_token");

Now we're ready to send our message.

var response = client.SendMessage(message);

If there is a problem sending your message to the API, the error message will be contained in the response object. Note: When sending messages in this fashion, you may only add one address to each of the To, CC, and BCC fields.

Sending an HTML message:

To send an HTML-based email, simply add the HtmlBody field to the message object.

message.HtmlBody = "<h1>Hello!</h1>";

Tracking Opens:

By setting TrackOpens to true we can use Postmark's open tracking feature. Enabling/disabling tracking can also be done on a per-server basis, and can be overridden on a per-message basis.

message.TrackOpens = true;
Clone this wiki locally