For the complete site index, see llms.txt. Docs index: llms-docs.txt. Marketing corpus: llms-full.txt. Docs corpus: llms-full-docs.txt. Prefer markdown URLs where available (append .md).. Product skill: skill.md. Pricing: pricing.md. Docs MCP: /docs/mcp.

AI & Automation/

How to Use AI to Generate Transactional Email Templates

Pranav Patel

Pranav Patel

Co-founder·9 min read

How to Use AI to Generate Transactional Email Templates
Summary

A practical workflow for generating transactional email templates with an LLM: a prompt that produces email-safe HTML, variable naming, review checks, and saving and sending the result as a Reloop template.

LLMs are good at writing transactional email templates if you constrain them hard. Tell the model exactly what email clients can render (tables, inline styles, 600px wide, no scripts), name every variable up front, and treat the output as a draft that goes through the same checks as hand-written HTML. Generate the template once, save it, and send it by ID. Don't call a model on every send.

This guide walks through the workflow we use: the prompt, the review checklist, and how to store and send the result as a Reloop template.


Generate once, send many times

There are two ways to use AI for transactional email, and only one of them is a good idea for most teams.

Approach
How it works
Use it for
Generate the template
An LLM writes the HTML once. You review it, save it, and send it with variables.
Receipts, password resets, welcome emails, invoices: almost everything
Generate every email
An LLM writes a new body for each recipient at send time.
Genuinely one-off messages, like an agent replying in a support thread

Generating per send is slower, costs money on every email, and means nobody has reviewed the exact HTML a customer receives. A password reset shouldn't depend on a model being in a good mood. Generate the template, then let variables do the personalization.


What email-safe HTML means

Most bad AI email templates fail for the same reason: the model writes web HTML. Email clients are not browsers. Outlook on Windows renders with Word's engine, Gmail strips <style> blocks in some contexts, and nobody runs your JavaScript.

Rule
Why
Layout with <table>, not flexbox or grid
Outlook ignores modern CSS layout
Inline every style (style="…")
Some clients drop <head> styles
Max width 600px, centered
Fits every desktop and mobile client
No <script>, forms, or iframes
Stripped or flagged as suspicious
Absolute https:// URLs for images and links
Relative URLs break outside your site
alt text on every image
Images are often blocked by default
Web-safe font stack
Custom fonts don't load in most clients
A bulletproof button (table cell with a link)
CSS-only buttons fall apart in Outlook

Put these rules in the prompt. Don't hope the model knows them.


The prompt

A good template prompt has four parts: context, constraints, variables, and output format.

text
1You write transactional email templates for {product}, a {one-line description}.
2
3Write the "{template name}" email. It is sent when {trigger event}.
4The reader's state: {what they just did, what they need next}.
5Tone: {plain, friendly, short}. No marketing copy, no emojis.
6
7Constraints:
8- A complete HTML document, email-safe: tables for layout, inline styles only,
9 600px max width, no <script>, no external CSS, web-safe fonts.
10- One primary call-to-action as a bulletproof table button.
11- Every image uses an absolute https URL and has alt text.
12- Include a short footer with the company name and a support email.
13
14Variables (use exactly these, in triple braces, and no others):
15- {{{first_name}}}: the recipient's first name
16- {{{reset_url}}}: the password reset link
17- {{{expires_in}}}: e.g. "30 minutes"
18
19Return only the HTML document. Then, after a line with "---", a subject line
20that may use the same variables.

Three things matter more than everything else:

  1. Declare the variables. If you don't list them, the model invents names ({{user.name}}, [FIRST NAME]) that won't be substituted.
  2. Describe the trigger. "Sent 1 minute after signup, before they've created a project" produces a much better welcome email than "write a welcome email".
  3. Ask for plain copy. Transactional email should read like a note from a person, not a landing page.

Generating it with the Claude API

You can use any capable model. Here's the same prompt sent with the Anthropic TypeScript SDK:

typescript
1import Anthropic from "@anthropic-ai/sdk";
2
3const anthropic = new Anthropic();
4
5const message = await anthropic.messages.create({
6 model: "claude-sonnet-5-5",
7 max_tokens: 8000,
8 system: TEMPLATE_SYSTEM_PROMPT, // the constraints above
9 messages: [
10 {
11 role: "user",
12 content:
13 "Write the password reset email for Acme. Variables: " +
14 "{{{first_name}}}, {{{reset_url}}}, {{{expires_in}}}.",
15 },
16 ],
17});
18
19const output = message.content
20 .filter((block) => block.type === "text")
21 .map((block) => block.text)
22 .join("");
23
24const [html, subject] = output.split("\n---\n").map((part) => part.trim());

For a handful of templates, you don't need code at all. Paste the prompt into Claude, iterate in the conversation ("make the button full-width on mobile", "shorter intro"), and copy the final HTML.

If you use the Reloop MCP server in Claude, Cursor or another MCP client, you can skip the copy-paste: ask the assistant to write the template and save it, and it calls the create_template tool with the HTML directly.


Review before you save

An LLM's template is a first draft. Run every one through the same checklist.

Check
How
Variables are exactly the ones you declared
Search the HTML for {{{; nothing else should appear
No leftover placeholders
Search for [, TODO, example.com, lorem
Links are real and absolute
Every href starts with https:// or is a variable
Renders in Outlook and Gmail
Send a test to real accounts in both
Dark mode is readable
Open the test on a phone in dark mode
Plain-text version makes sense
Read the text part, not just the HTML
Under 100 KB of HTML
Gmail clips larger messages
Copy is accurate
Expiry times, support address and product names are right

The last one is the one models get wrong most often. A model will happily write "this link expires in 24 hours" when your links expire in 30 minutes. Pass facts like that in as variables or state them in the prompt.


Save it as a Reloop template

Saved templates live in Reloop, get version history, and can be edited later in the visual editor. You send them by ID or slug and pass the variables at send time.

In the dashboard

Open Templates → New template. The visual editor has a built-in AI assistant, so you can describe the email, generate a layout, and refine it in place. Placeholders are detected as template variables, and you can set a default for each one.

If you generated the HTML somewhere else, save it with the API below or with the MCP create_template tool. Both store the full HTML document as-is.

With the API

Create the template, then publish a version with the rendered HTML:

typescript
1const headers = {
2 "x-api-key": process.env.RELOOP_API_KEY!,
3 "Content-Type": "application/json",
4};
5
6const content = [{ id: crypto.randomUUID(), type: "html", props: {}, html }];
7
8const created = await fetch("https://reloop.sh/api/template/v1/create", {
9 method: "POST",
10 headers,
11 body: JSON.stringify({ name: "Password reset", subject, content }),
12}).then((res) => res.json());
13
14await fetch(`https://reloop.sh/api/template/v1/${created.id}/versions`, {
15 method: "POST",
16 headers,
17 body: JSON.stringify({
18 content,
19 subject,
20 renderedHtml: html,
21 isMajor: true, // publish this version
22 variables: [
23 { name: "first_name", type: "string", defaultValue: "there" },
24 { name: "reset_url", type: "string", defaultValue: null },
25 { name: "expires_in", type: "string", defaultValue: "30 minutes" },
26 ],
27 }),
28});

Sends always use the latest published version, so you can save drafts and review changes without affecting live email.

Send a test

Before you wire it into your app, send a test with real-looking variables:

bash
1curl -X POST "https://reloop.sh/api/template/v1/$TEMPLATE_ID/test" \
2 -H "x-api-key: $RELOOP_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{"to":"you@example.com","variables":{"first_name":"Ada","reset_url":"https://acme.com/reset/abc","expires_in":"30 minutes"}}'

Send it from your app

typescript
1import { Reloop } from "reloop-email";
2
3const reloop = new Reloop({ apiKey: process.env.RELOOP_API_KEY! });
4
5const { emailError } = await reloop.mail.send({
6 from: "Acme <security@mail.acme.com>",
7 to: user.email,
8 subject: "Reset your password",
9 template: {
10 id: process.env.RESET_TEMPLATE_ID!,
11 variables: {
12 first_name: user.firstName,
13 reset_url: resetUrl,
14 expires_in: "30 minutes",
15 },
16 },
17});

A few details worth knowing:

  • Defaults fill gaps. If you leave a variable out, Reloop uses the template's default. If there's no default, the placeholder stays as-is, so set defaults for anything optional.
  • Plain text is automatic. If the template has only HTML, Reloop derives the text/plain part from it, so the email still goes out as multipart.
  • Subject comes from the template when the template has one, with variables substituted there too.

Iterating with AI

Templates aren't write-once. A useful loop:

  1. Look at the numbers in your Reloop logs: opens, clicks, and how many people complete the action.
  2. Ask the model for a variant that targets the weak spot ("the CTA is below the fold on mobile", "the first sentence doesn't say why they got this email").
  3. Save it as a new version, test it, publish it.
  4. If it's worse, restore the previous version from the template's history.

Keep the variables identical between versions so your send code never changes. To send the finished template from an AI app, see Vercel AI SDK + Reloop.


Prompt snippets for common templates

Template
Trigger to describe
Variables
Welcome
Account created, nothing set up yet
first_name, dashboard_url
Email verification
Signed up, must confirm address
verify_url, expires_in
Password reset
Requested a reset
first_name, reset_url, expires_in
Receipt
Payment succeeded
first_name, amount, invoice_url, date
Payment failed
Card declined on renewal
first_name, update_billing_url, retry_date
Team invite
Invited by a teammate
inviter_name, team_name, accept_url

For the content of each, see transactional email best practices.


FAQ

Any current frontier model writes good email HTML when the constraints are in the prompt. The constraints matter far more than the model. Pick one you can call from your stack and keep the prompt in version control.

Reloop substitutes {{{variable}}} placeholders when it renders a template at send time. Using that syntax in the prompt means the generated HTML works without find-and-replace.

Yes. Vision-capable models can match a reference image's layout and colors. Ask for email-safe HTML that approximates the design, then review it in real clients. Pixel-perfect matches aren't realistic in email.

For replies in a conversation, yes. For system emails like receipts and resets, no. See building an AI agent that sends emails for where per-message generation makes sense.

W: 320.0px180R20∠45.0°

Ship your first email with Reloop
in minutes.

Open-source, deliverability-focused, and yours to self-host or run on Reloop Cloud. No lock-in, no rewrite later.

Reloop