Prompt

How do I build email templates with variables for a SaaS app?

Technology / API Platforms1 observationLast seen Nov 6, 2026

Latest observation

Nov 6, 2026OpenAI APIWeb search: off

A good way to build email templates for a SaaS app is to separate:

  1. Template content
  2. Variable data
  3. Rendering logic
  4. Delivery system

That gives you reusable emails, easy customization, and safer maintenance.

1) Choose a template format

Common options:

  • Handlebars / Mustache: simple variables and basic conditionals
  • MJML: makes responsive email HTML easier
  • React email: component-based, good if your app already uses React
  • Liquid: popular in SaaS and marketing tools
  • Plain HTML + placeholders: simplest, but gets messy fast

A common setup is:

  • Use MJML or React Email for layout
  • Use Handlebars/Liquid-style variables for dynamic text

Example placeholder style:

<p>Hello {{first_name}},</p>
<p>Your invoice {{invoice_number}} is ready.</p>

2) Define your variables clearly

Create a schema for each template so you know what data it expects.

Example:

{
  "first_name": "Jane",
  "company_name": "Acme Inc",
  "invoice_number": "INV-1024",
  "cta_url": "https://app.example.com/invoices/INV-1024"
}

Best practices:

  • Use consistent naming like first_name, company_name
  • Keep variables specific to the template
  • Provide defaults for missing values
  • Support conditional sections for optional fields

Example:

{{#if first_name}}
  Hi {{first_name}},
{{else}}
  Hi there,
{{/if}}

3) Store templates in a manageable way

You have a few choices:

Option A: In code

Best for:

  • small teams
  • product emails
  • version control

Store templates in your repo as files:

  • welcome_email.mjml
  • password_reset.hbs

Option B: In a database or CMS

Best for:

  • non-developers editing templates
  • marketing teams
  • frequent changes

Store:

  • template name
  • subject line
  • body HTML
  • version
  • enabled status

Option C: Hybrid

  • Core transactional templates in code
  • Marketing templates in an admin UI or CMS

This is often the best SaaS approach.

4) Render templates server-side

When sending email:

  1. Fetch the template
  2. Merge it with variables
  3. Render HTML/text
  4. Send through email provider

Pseudo-flow:

const template = getTemplate("welcome_email");
const html = render(template.html, {
  first_name: user.firstName,
  company_name: user.companyName
});
sendEmail({
  to: user.email,
  subject: "Welcome to ExampleApp",
  html
});

Important:

  • Always render on the backend
  • Never let clients directly construct raw email HTML for production sends
  • Escape variables by default to prevent injection

5) Include both HTML and text versions

Email deliverability improves when you send:

  • HTML email
  • plain-text fallback

Example:

  • HTML: designed template
  • Text: simple readable version

Many libraries can generate the text version automatically.

6) Support reusable components

For SaaS emails, create shared pieces like:

  • header
  • footer
  • buttons
  • legal block
  • brand styles

This prevents repeated code across templates.

Example components:

  • EmailLayout
  • PrimaryButton
  • FooterLinks

7) Handle localization

If you serve multiple languages:

  • Keep template keys separate from copy
  • Pass localized strings into templates
  • Avoid hardcoding language in HTML

Example:

{
  "subject": "Reset your password",
  "greeting": "Hello",
  "cta_text": "Reset password"
}

8) Version your templates

Emails often change over time. Track:

  • template version
  • last updated
  • who edited it
  • rollback option

This helps prevent broken emails after updates.

9) Test rendering before sending

Test with:

  • missing variables
  • long names
  • special characters
  • mobile clients
  • dark mode

Use preview data:

{
  "first_name": "Alex",
  "invoice_number": "INV-9999"
}

10) Use an email service provider

For sending, use:

  • SendGrid
  • Mailgun
  • Postmark
  • Amazon SES
  • Resend

These can handle:

  • SMTP/API delivery
  • bounce tracking
  • open/click tracking
  • templates in some cases

Recommended architecture for a SaaS app

A practical setup:

  • Template files in repo or DB
  • Variable schema per template
  • Backend renderer using Handlebars/Liquid/React Email
  • Email provider for delivery
  • Preview/testing tool for QA
  • Versioned templates for safety

Example simple implementation

Template

<!doctype html>
<html>
  <body>
    <h1>Welcome, {{first_name}}!</h1>
    <p>Your account for {{company_name}} is ready.</p>
    <a href="{{cta_url}}">Get started</a>
  </body>
</html>

Data

{
  "first_name": "Sam",
  "company_name": "Acme",
  "cta_url": "https://app.example.com/start"
}

Render and send

import Handlebars from "handlebars";

const template = `
  <h1>Welcome, {{first_name}}!</h1>
  <p>Your account for {{company_name}} is ready.</p>
  <a href="{{cta_url}}">Get started</a>
`;

const html = Handlebars.compile(template)({
  first_name: "Sam",
  company_name: "Acme",
  cta_url: "https://app.example.com/start"
});

My recommendation

If you're building a SaaS app from scratch:

  • Use Handlebars or Liquid for variables
  • Use MJML or React Email for layout
  • Render server-side
  • Store template metadata + version + variable schema
  • Keep HTML + text versions
  • Add a preview/testing workflow

If you want, I can also give you:

  1. a database schema for email templates,
  2. a Node.js implementation, or
  3. a React Email / MJML example.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.