Developing Marketing Email Templates
Marketing emails — promotions, announcements, news digests, win-back emails — differ from transactional ones with a freer structure and focus on conversion. They need eye-catching headlines, quality banner images, clear CTA, and compatibility with email clients from Outlook 2016 to Apple Mail on iOS.
Stack: MJML + Handlebars
MJML works well for marketing templates — it handles tables and media-queries, while Handlebars inserts variables like {{firstName}} and iterates through {{#each products}}.
Typical promotional email structure:
<mjml>
<mj-head>
<mj-preview>30% off until Friday only — don't miss out</mj-preview>
<mj-attributes>
<mj-all font-family="'Helvetica Neue', Helvetica, Arial, sans-serif" />
<mj-text font-size="16px" line-height="1.6" color="#374151" />
</mj-attributes>
</mj-head>
<mj-body background-color="#f3f4f6">
<!-- Hero banner -->
<mj-section background-color="#1e40af" padding="48px 32px">
<mj-column>
<mj-image src="{{ logoUrl }}" width="140px" align="left" />
<mj-text font-size="36px" font-weight="800" color="#ffffff" padding-top="24px">
Final Clearance
</mj-text>
<mj-text font-size="18px" color="#bfdbfe">
Up to 50% off everything — only until {{endDate}}
</mj-text>
<mj-button href="{{ saleUrl }}" background-color="#f59e0b"
color="#111827" font-weight="700" border-radius="8px">
Shop Now
</mj-button>
</mj-column>
</mj-section>
<!-- Three products in a row -->
<mj-section background-color="#ffffff" padding="32px">
{{#each products}}
<mj-column width="33%">
<mj-image src="{{ this.imageUrl }}" border-radius="8px" />
<mj-text font-weight="600" color="#111827">{{ this.name }}</mj-text>
<mj-text>
<s style="color:#9ca3af">{{ this.oldPrice }}</s>
<span style="color:#dc2626;font-weight:700">{{ this.newPrice }}</span>
</mj-text>
<mj-button href="{{ this.url }}" background-color="#3b82f6" border-radius="6px">
Buy
</mj-button>
</mj-column>
{{/each}}
</mj-section>
<!-- Footer -->
<mj-section padding="16px 32px">
<mj-column>
<mj-text font-size="12px" color="#9ca3af" align="center">
You received this email because you subscribed to our newsletter.<br/>
<a href="{{ unsubscribeUrl }}" style="color:#9ca3af">Unsubscribe</a>
·
<a href="{{ preferencesUrl }}" style="color:#9ca3af">Preferences</a>
</mj-text>
</mj-column>
</mj-section>
</mj-body>
</mjml>
Rendering and Sending
import mjml2html from 'mjml';
import Handlebars from 'handlebars';
import { readFileSync } from 'fs';
function renderMarketingEmail(
templateName: string,
data: Record<string, unknown>
): string {
const template = readFileSync(`./email-templates/${templateName}.mjml`, 'utf-8');
const compiled = Handlebars.compile(template)(data);
const { html, errors } = mjml2html(compiled, { minify: true });
if (errors.length) throw new Error(errors[0].formattedMessage);
return html;
}
Dynamic Content
Marketing emails often require personalization based on user data:
-
Products from browsing history — SQL query by
user_id, top-3 categories -
Name and greeting —
{{firstName}}with fallback "Dear Subscriber" - Geolocation — different offers by country/city via conditional Handlebars
-
UTM tags —
?utm_source=email&utm_campaign=spring_saleadded to all links







