Prompt
How do I create a template with dynamic variables for app emails?
Latest observation
Nov 6, 2026
OpenAI APIWeb search: off
To create an email template with dynamic variables for app emails, you usually:
-
Choose a template format
- Plain HTML with placeholders, or
- A templating language like Handlebars, Mustache, Liquid, or EJS
-
Define placeholders for dynamic data Example:
<h1>Hello {{firstName}}</h1> <p>Your order #{{orderNumber}} has shipped.</p> -
Store the template
- In your codebase, a database, or a template service
- Keep variables consistent and documented
-
Render the template at send time Replace placeholders with real values from your app:
const template = "Hello {{firstName}}, your code is {{code}}"; const rendered = template .replace("{{firstName}}", "Ava") .replace("{{code}}", "123456"); -
Send the rendered email Use your email provider (SendGrid, SES, Mailgun, Postmark, etc.)
Example with Handlebars
Template:
<p>Hi {{firstName}},</p>
<p>Welcome to {{appName}}!</p>
<p>Your verification code is <strong>{{verificationCode}}</strong>.</p>
Data:
{
firstName: "Ava",
appName: "MyApp",
verificationCode: "123456"
}
Rendered output:
<p>Hi Ava,</p>
<p>Welcome to MyApp!</p>
<p>Your verification code is <strong>123456</strong>.</p>
Best practices
- Use clear variable names like
firstName,resetLink,expiryMinutes - Provide default values if data is missing
- Escape user-provided content to avoid injection issues
- Keep templates modular if you have multiple email types
- Preview/test templates before sending
If you want, I can show you:
- a Node.js example
- a Python example
- or a SendGrid/Mailgun/Postmark setup