Use templates to create an email design and store frequently used content to reuse in different transactional emails. You can store templates in Transactional Email, and then send emails containing dynamic recipient-specific content.
Advantages of Using Templates in Transactional Email
-
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 Transactional Email account.
Add Templates to Your Account
There are a few ways to add templates to a Transactional Email account:
-
Custom code a template and send it to your Transactional Email account via the API.
-
Add templates via the Templates page in your Transactional Email account to use the Transactional Email code editor to custom code your template or paste your template code.
-
Send a template from your Mailchimp account to your connected Transactional Email account.
Template Fields
Templates consist of several default options or fields in Transactional Email, including a default subject line, sender, HTML content, and text content. None of these fields are required when creating or changing 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 Transactional Email 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 Transactional Email account, on a per-message basis using the inline_css
option (API) or X-MC-InlineCSS
header (SMTP), or using the Transactional Email Rules Engine.
CSS inlining can be an intensive process and since Transactional Email 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.
Transactional Email will inline CSS only for HTML emails smaller than 256KB.