-
Notifications
You must be signed in to change notification settings - Fork 48
Sending Using a Template
Before trying to send email using Postmark Templates from .net, we recommend reviewing how the Postmark Templates feature works.
-
Create a Template. This can be done via the API, or using our editor from a server dashboard at https://postmarkapp.com. Each template created is assigned an
Id
, this will be used when sending a templated email: -
Create a message object, assigning a
TemplateModel
var message = new TemplatedPostmarkMessage();
// Set normal message properties:
message.From = "[email protected]";
message.To = "[email protected]";
// Set which template should be used for this email.
message.TemplateId = <Template Id from Step 1>;
// These are the values that will be merged with your template
// You can use a POCO, or Dictionary<Key,Value> here.
// You **cannot** use scalar values or collections for TemplateModel
// (though they can be used _inside_ of a model.)
message.TemplateModel = new {
Name = "Johnny"
Company = "Wildbit"
}
- Finally, send the email:
var client = new PostmarkClient("<server token>");
await client.SendMessageAsync(message);
You may send an Array
or IEnumerable
of TemplatedPostmarkMessage
objects in one call to the API. This is more efficient than sending emails individually, but consider bandwidth and message payload limits to determine how many messages to send at once.
Please note that batch endpoints will return a 200-level Http Status, even when validation for individual messages may fail. Users of these endpoints should check the error code for each message in the response from our API (the results are ordered the same as the original messages).
var client = new PostmarkClient("<server token>");
// Generate an array of TemplatedPostmarkMessage objects.
var messages = CreateBatchOfTemplatedEmails();
// Send the messages.
var results = await client.SendMessagesAsync(messages);
// Iterate over each result to confirm the message was sent successfully.
foreach(var result in results){
if(result.ErrorCode != 0){
//Recover from issue.
}
}
The Postmark.Net client can be installed from NuGet.
For additional information about the capabilities of the Postmark API, see http://developer.postmarkapp.com/.
- Getting Started
- Version 2.0 Upgrade Guide
- Sending Email
- Searching Sent Messages
- Analyzing Sent Messages
- Processing Inbound Email
- Retrieving Message Statistics
- Handling Bounces
- Managing Suppressions
- Working with Message Streams
- Managing Your Account
- Troubleshooting Async&Await
- Version 1.x Overview
- Sending Email
- Sending Batch Emails
- Sending Attachments
- Sending Inline Images
- Using
MailMessage
- Using the Bounce API
- [Getting Send Statistics](Sending Statistics)
- Adding Custom Email Headers