Skip to content

Instantly share code, notes, and snippets.

@jptoto
Created October 2, 2015 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jptoto/374969e4c436226aa741 to your computer and use it in GitHub Desktop.
Save jptoto/374969e4c436226aa741 to your computer and use it in GitHub Desktop.
PM Async Example
// Send an email with the Postmark .NET library
// Learn more -> http://developer.postmarkapp.com/developer-official-libs.html#dot-net
// Install with NuGet
PM> Install-Package Postmark
// Import
using PostmarkDotNet;
// Example asynchronous request
var message = new PostmarkMessage()
{
To = "recipient@example.com",
From = "sender@example.com",
TrackOpens = true,
Subject = "A complex email",
TextBody = "Plain Text Body",
HtmlBody = "<html><body><img src=\"cid:embed_name.jpg\"/></body></html>",
Tag = "New Year's Email Campaign",
Headers = new HeaderCollection{
{"X-CUSTOM-HEADER", "Header content"}
}
};
var imageContent = File.ReadAllBytes("test.jpg");
message.AddAttachment(imageContent, "test.jpg", "image/jpg", "embed_name.jpg");
var client = new PostmarkClient("<server token>")
var sendResult = await client.SendMessageAsync(message);
if (sendResult.Status == PostmarkStatus.Success){ /* Handle success */ }
else { /* Resolve issue.*/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment