Prompt
How do I create reusable email templates for password resets and alerts?
Latest observation
Nov 6, 2026
OpenAI APIWeb search: off
A good way to make reusable email templates is to separate content, layout, and dynamic data so you can reuse the same template structure for password resets, alerts, verification emails, etc.
1) Use a template engine
Common options:
- MJML for responsive email markup
- Handlebars / Mustache / Liquid for placeholders
- Framework-specific templating if you’re already in one:
- Django templates
- Jinja2
- Razor
- EJS/Nunjucks
Example placeholder style:
<p>Hello {{firstName}},</p>
<p>Click here to reset your password: <a href="{{resetLink}}">Reset Password</a></p>
2) Create a base email layout
Make one shared layout with:
- header/logo
- body container
- footer
- consistent button styles
- unsubscribe/help links if needed
Then each email type injects its own content into that layout.
Example concept:
<html>
<body>
<table>
<tr><td><img src="{{logoUrl}}" alt="Company"></td></tr>
<tr><td>{{content}}</td></tr>
<tr><td>{{footerText}}</td></tr>
</table>
</body>
</html>
3) Build separate reusable templates for each email type
Keep a dedicated template per use case:
- password_reset
- account_alert
- email_verification
- security_notification
Each template should only define the body text and variables it needs.
Password reset example
<h1>Password reset request</h1>
<p>Hi {{firstName}},</p>
<p>We received a request to reset your password.</p>
<p><a href="{{resetLink}}">Reset your password</a></p>
<p>This link expires in {{expiresIn}}.</p>
Alert example
<h1>Security alert</h1>
<p>Hi {{firstName}},</p>
<p>We noticed a new login from {{location}} on {{dateTime}}.</p>
<p>If this was not you, please secure your account immediately.</p>
4) Pass data into templates from code
Your app should render the template with variables at send time.
Example pseudo-code:
sendEmail({
template: "password_reset",
to: user.email,
data: {
firstName: user.firstName,
resetLink: generateResetLink(user),
expiresIn: "30 minutes"
}
});
5) Store templates in a structured way
Good approaches:
- Files in a
/templates/emails/directory - Database-backed templates if non-developers need to edit them
- Use version control for changes
Example folder structure:
templates/
emails/
layout.html
password_reset.html
account_alert.html
6) Make them responsive and email-safe
Email clients are picky. Best practices:
- Use tables for layout
- Inline CSS
- Avoid heavy JS
- Test in Gmail, Outlook, Apple Mail
- Use absolute URLs for images/links
7) Include tokenized links and expiry
For password resets and alerts:
- Use secure, single-use tokens
- Add expiration timestamps
- Avoid exposing sensitive info in the email body
8) Preview and test
Set up:
- local preview pages
- seed test data
- spam/link checks
- rendering tests across clients
9) Consider personalization
Reusable templates become more useful with:
- first name
- account type
- last login time
- device/location for alerts
If you want, I can also give you:
- a sample HTML/CSS email template,
- a Node.js example using Handlebars, or
- a Python/Django version.