Set up DMARC and see who's sending email using your brand's domain.
x

Templates FAQ

How do I copy a template from one server to another server?#

Open the template you want to duplicate. Next to the Save button, click the dropdown arrow and then select Duplicate. Enter the template name and select the server you want to copy the template to, then click Duplicate. You can then open the copied template or return to the original Template.

How do I copy all templates from one server to another server?#

Using the UI

  1. Open the server containing the templates you want to push to another server and head to the Templates page.
  2. Click the Push to another server button.
  3. Select the destination server you want to push the template(s) to.
  4. You will see a preview of the templates heading to the destination server, along with whether they will be created for the first time (+ icon) or will update an existing template (pencil icon). Click the Preview button if you want to preview the changes. Click Push now to complete the push of the templates to the destination server.

Using the Templates API

Templates can be copied from a source server to another server using the Templates API as well.

Use this option for programmatically keeping your templates in sync across multiple environments or giving your users a way to sync template changes from your own UI.

Method: PUT

Endpoint: https://api.postmarkapp.com/templates/push

JSON Body:

{
"SourceServerID": <source server id>,
"DestinationServerID": <destination server id>,
"PerformChanges": true
}

Example curl command:

curl "https://api.postmarkapp.com/templates/push" \
-X PUT \
-H "Accept: application/json" \
-H "X-Postmark-Account-Token: <account API token>" \
-d "{"SourceServerID":<source server id>, "DestinationServerID":<destination server id>, "PerformChanges":true}”

Is there a limit on the number of templates I can create per server?#

Yes — you can create up to 100 templates per server.

Is there a limit on the number of templates I can push at once?#

Yes — you can push up to 100 templates at a time.

How do I add an unsubscribe link to my template?#

Every message sent through a Broadcast Message Stream in Postmark is required to have an unsubscribe link. If you're sending with Postmark's Templates you can add an unsubscribe placeholder with its HTML:

{{{ pm:unsubscribe }}}

By default, the unsubscribe link will have a text of "Unsubscribe". To change the default text, treat the unsubscribe placeholder as a hyperlink:

<a href=”{{{ pm:unsubscribe }}}”>Unsubscribe from this list</a>

Unsubscribe links included in Templates will also work for messages sent through Transactional Message Streams, though they are not required. Read our helpful guide on how to add unsubscribe links to your templates.

How do I localize my templates for different languages?#

Although Mustachio doesn't include explicit support for localizing templates, in many cases, only minor adjustments are needed in the content of a template, so it's simple to include the variations inline.

For example, let's create a basic template that can use different language for Spanish, or English languages:

<html>
   <body>
      {{#english}}Good morning, {{../name}}{{/english}}
      {{#spanish}}Buenos días, {{../name}}{{/spanish}}
   </body>
</html>

Given a model like this:

{
  "english" : true,
  "name" : "Dave"
}

The template would produce the following result:

<html>
   <body>
     Good morning, Dave
   </body>
</html>

Note that the presence of the "spanish" property is not necessary.

Many templates require only small modifications to their content for them to be properly localized, but this same technique could be used to create a large block of localized content for each target language. Additionally, using our advanced scoping features ../, it's possible to navigate up and around the template model for more complex scenarios.

How do I use an ‘If’ statement?#

You might have noticed, Mustachio doesn't have any if-else syntax built in. This was done deliberately in Mustache, for some good reasons, and we tried to keep Mustachio as close to Mustache as we could.

Does this mean you can't show or hide content conditionally?

Of course not! Mustache and Mustachio allow you a great amount of flexibility, but the flow control is more"declarative" than"imperative." So what does this mean?

Testing for Existence

The key difference between the way we'd choose to conditionally execute application code, and the way we choose what to render is based on whether a value is present in a model, or absent ("truthy" or "falsey"). So, let's take a simple case and show how you can both render content when a value is present, and when it is absent:

An Example Template:

Dear {{#name}}{{.}}{{/name}}{{^name}}{{../job_title}}{{/name}}

This template will either:

  1. Render name if it is"truthy" or,
  2. Render job_title if it is not present:

(Make special note of the {{ . }} syntax to reference name and {{ ../job_title }} to "move up" a level in the scope.)

Now, let's have a look at what the output is for a few different models:

Here's an example where name is present:

Model:

{
  "name" : "Alice",
  "job_title" : "CEO"
}

Result:

Dear Alice

Here's an example where name is absent:

Model:

{
  "job_title" : "CEO"
}

Result:

Dear CEO

name may also be false or null and will produce the same result as when absent:

Model:

{
  "name" : null,
  "job_title" : "CEO"
}

Result:

Dear CEO

It may seem a bit odd to author templates without explicitly including conditionals, but hopefully it's clear that one can achieve the same results with "logic-less templates," while requiring remembering less syntax.

How do I set the Subject at the time of sending when using a Template?#

The way to do this is to add variables to your Template subject.

With Templates, you can either set a default subject that is the same for every email sent using that Template or you can also use Template variables to make the subject dynamic. You cannot set the "Subject" field in your JSON to send the email directly, like you can when sending a message that does not use a Template.

For a dynamic subject example, let's say you had your subject set like this in the Template:

Screen-Shot-2018-02-20-at-1-18-15-PM.png

You could then pass in a product_name and name value in your Template model at the time of sending to have those values reflected in the subject of the email.

You could even set your Subject for the Template to just {{ subject }} and then populate the full subject in your Template model.

The key thing to remember is that the Subject field for the Template can be set up to use Template variables, which you then populate in your Template model when sending, like you would for your other variables in the Template.

ErrorCode 1122#

Check if you have a <link> tag in your <head> in the Template HTML. This is not supported and will cause the error.

Can I send a batch of emails with the API using a Template?#

Yes! You can send an array of messages to send that use templates to the batch endpoint.

Below is an example API request body to /email/batchWithTemplates for two emails using templates, so you can see what the JSON format looks like.

{
  "Messages": [
    {
      "From": "sender@example.com",
      "To": "receiver@example.com",
      "Cc": "copied@example.com",
      "Bcc": "blank-copied@example.com",
      "Tag": "Invitation",
      "ReplyTo": "reply@example.com",
      "TemplateAlias": "invitation-letter",
      "TemplateModel": {
        "fizz": "buzz"
      },
      "Headers": [
        {
          "Name": "CUSTOM-HEADER",
          "Value": "value"
        }
      ],
      "TrackOpens": true,
      "TrackLinks": "None",
      "Attachments": [
        {
          "Name": "readme.txt",
          "Content": "dGVzdCBjb250ZW50",
          "ContentType": "text/plain"
        },
        {
          "Name": "report.pdf",
          "Content": "dGVzdCBjb250ZW50",
          "ContentType": "application/octet-stream"
        },
        {
          "Name": "image.jpg",
          "ContentID": "cid:image.jpg",
          "Content": "dGVzdCBjb250ZW50",
          "ContentType": "image/jpeg"
        }
      ]
    },
    {
      "From": "sender@example.com",
      "To": "receiver2@example.com",
      "Cc": "copied2@example.com",
      "Bcc": "blank-copied2@example.com",
      "Tag": "welcome",
      "ReplyTo": "reply2@example.com",
      "TemplateAlias": "welcome-email",
      "TemplateModel": {
        "fizz": "buzz"
      },
      "Headers": [
        {
          "Name": "CUSTOM-HEADER",
          "Value": "value"
        }
      ],
      "TrackOpens": true,
      "TrackLinks": "None",
      "Attachments":  null
    }
  ]
}

Can I use POSTMARK_API_TEST to test sending with a Template?#

This test token (POSTMARK_API_TEST) does not work with the API endpoint for sending using a Template. Since the POSTMARK_API_TEST token is not associated with a particular account or server, your unique Template IDs cannot be matched to the test token. This test token can only be used for testing sending a single email not using a Template or a batch of emails.

If you want to test a Template and do not need to actually receive the sent test email, you can send using your Server API Token to test@blackhole.postmarkapp.com. We will then show the send in your Activity but you do not receive an email for the test in an inbox.

How do I use a template alias?#

If you wish to reference a template by an alias instead of its Template ID, you can set an alias that you then use in your API call to send an email with the template. To set an alias, edit the template using a PUT call to https://api.postmarkapp.com/templates/{templateID} with the alias you want to set included in the body:

{
  "Name": "Template Name",
  "Alias": "my-alias"
}

Once you have your alias set, you can now use it to send an email with that template. You will still send the request to send to the same endpoint but instead of including a "TemplateId" field for identifying the template, you will use your alias for the template in a "TemplateAlias" field, like this:

{
  "TemplateAlias": "my-alias",
  "TemplateModel": {
    "user_name": "John Smith",
    "company": {
      "name": "ACME"
    }
  },
  "From": "sender@example.com",
  "To": "receiver@example.com"
}
Last updated August 16th, 2022

Still need some help?

Our customer success team has your back!