Getting Started with Templates

Use templates to create an email design and store frequently-used content to reuse in different transactional emails. Store templates in Mandrill, then send email using the template and provide dynamic recipient-specific content.

Advantages of Using Templates in Mandrill

  • Efficiency—API calls only need to provide the information that's different or the dynamic portions of the content when you send an email. This simplifies the payload, and can reduce the amount of data you're transmitting.

  • Non-developers can edit template design and copy in your Mandrill account.

Add Templates to Your Account

There are a few ways to add templates to a Mandrill account:

  • Custom code a template and send it to your Mandrill account via the API.

  • Add templates via the Templates page in your Mandrill account to use the Mandrill code editor to custom code your template or paste your template code.

    Mandrill template editor

  • Send a template from your MailChimp account to your connected Mandrill account.

Template Fields

Templates consist of several default options or fields in Mandrill, including a default subject line, sender, HTML content, and text content. None of these fields are required when creating or modifying a template, but if you're planning to use messages/send-template, you'll want to be sure to have either HTML or text specified since these will form the content of the body of your email.

Note: None of the fields are required, because in addition to the send-template API call or specifying a template through SMTP headers, you can also apply templates using the Rules Engine or for A/B split testing.

Placeholders for Custom or Dynamic Content

Since templates are often reusing large bits of content, you'll probably want to include a way to inject more customized content for a particular email that's being sent. For example, when sending a receipt instead of a password reset, or because you want to include a greeting with the recipient's name.

If you're not using MailChimp templates, or aren't familiar with the MailChimp template language, you'll probably want to use Handlebars to add your custom content (Handlebars is the most flexible option we offer). For MailChimp users, or if you're already using MailChimp templates, we also support the MailChimp template language and merge tags.

Inline CSS

Email clients typically support only a subset of valid HTML, and don’t have strong support for CSS (especially CSS in the <head> of the HTML email). Yahoo, Outlook, and even Gmail strip CSS that’s included in the <head> of your HTML, so in most cases CSS for email is handled using inline styles.

Rather than inlining your CSS manually before sending your HTML to Mandrill or when you’re generating a template, we provide a sending option to inline CSS automatically at the time of send (as long as your message is 256KB or smaller). Set this on the Sending Defaults page in your Mandrill account, on a per-message basis using the inline_css option (API) or X-MC-InlineCSS header (SMTP), or using the Mandrill Rules Engine.

CSS inlining can be an intensive process and since Mandrill is designed to get your emails out as quickly as possible, the additional processing time to inline CSS can affect delivery speeds. If you have a larger template or HTML document, it's best to inline your styles manually or by using a CSS inlining tool as a part of your sending process.

Mandrill will inline CSS only for HTML emails smaller than 256KB.