How to Use AI to Generate Transactional Email Templates
Pranav Patel
Co-founder·9 min read
On this page

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.
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.
<table>, not flexbox or gridstyle="…")<head> styles<script>, forms, or iframeshttps:// URLs for images and linksalt text on every imagePut 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.
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 name16- {{{reset_url}}}: the password reset link17- {{{expires_in}}}: e.g. "30 minutes"18
19Return only the HTML document. Then, after a line with "---", a subject line20that may use the same variables.Three things matter more than everything else:
- Declare the variables. If you don't list them, the model invents names (
{{user.name}},[FIRST NAME]) that won't be substituted. - 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".
- 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:
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 above9 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.content20 .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.
{{{; nothing else should appear[, TODO, example.com, loremhref starts with https:// or is a variableThe 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:
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 version22 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:
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
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/plainpart 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:
- Look at the numbers in your Reloop logs: opens, clicks, and how many people complete the action.
- 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").
- Save it as a new version, test it, publish it.
- 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
first_name, dashboard_urlverify_url, expires_infirst_name, reset_url, expires_infirst_name, amount, invoice_url, datefirst_name, update_billing_url, retry_dateinviter_name, team_name, accept_urlFor 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.
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.


