Prompt
How do I manage templates for app emails across dev, staging, and prod?
Latest observation
A good way to manage email templates across dev, staging, and prod is to treat them like application code, with version control, environment-specific config, and a safe promotion flow.
Recommended approach
1) Store templates in source control
Keep email templates in your repo, for example:
templates/emails/welcome.htmltemplates/emails/password_reset.htmltemplates/emails/invoice.txt
This gives you:
- code review
- history/rollback
- consistency across environments
2) Separate content from environment config
Use the same template code in all environments, but inject environment-specific values at runtime, such as:
- sender name
- reply-to address
- branding assets
- base URLs
- feature flags
- localization settings
Example:
- Dev:
support-dev@company.com, links point to dev app - Staging:
support-staging@company.com, links point to staging app - Prod: real support address and production links
3) Use environment variables for email settings
Keep configuration outside templates:
EMAIL_FROM_NAME=MyApp Dev
EMAIL_FROM_ADDRESS=no-reply-dev@myapp.com
EMAIL_REPLY_TO=support-dev@myapp.com
APP_BASE_URL=https://dev.myapp.com
Then swap these per environment.
4) Make templates parameterized
Design templates with placeholders instead of hardcoded values.
Example:
<p>Hello {{ first_name }},</p>
<p>Reset your password here: <a href="{{ reset_link }}">Reset Password</a></p>
This lets the same template work everywhere.
5) Use a templating system
Pick one depending on your stack:
- Node: Handlebars, Nunjucks, EJS
- Python: Jinja2
- Ruby: ERB
- Java: Thymeleaf, FreeMarker
Use shared partials/components for:
- header
- footer
- buttons
- legal text
6) Preview templates in each environment
Set up a preview/test harness so you can render the same template with sample data in dev/staging before sending real emails.
Useful for checking:
- responsive layout
- broken links
- missing variables
- dark mode quirks
- email client rendering
7) Add automated tests
Test at least:
- template renders with required data
- subject lines
- unsubscribe links
- localization
- fallback content
If possible, snapshot-test rendered HTML.
8) Promote changes through environments
A common flow:
- Develop and test in dev
- Validate rendering and copy in staging
- Promote the same template version to prod
Avoid editing prod templates manually unless there’s an emergency.
9) Consider a centralized template service if needed
If templates are managed by marketing/non-engineering teams or many services send email, use a system like:
- SendGrid Dynamic Templates
- Mailgun templates
- Amazon SES templates
- Customer.io / Braze / Iterable
Then your app passes variables, and template changes can be managed separately.
10) Protect production
For safety:
- use test recipients in dev/staging
- suppress real sends in non-prod
- add a banner or obvious label in non-prod emails
- verify no production customer data is used in staging
Simple practical setup
A solid default setup is:
- Templates in git
- Environment variables for branding and links
- Same template code in all environments
- Automated render tests
- Dev/staging email delivery sent to a sandbox or test inbox
- Prod only uses production SMTP/provider credentials
Example structure
email/
templates/
layout.html
welcome.html
password_reset.html
partials/
header.html
footer.html
tests/
render_welcome.test.js
Rule of thumb
If the email is part of app behavior, manage it like code.
If marketing needs to edit it frequently without deployments, consider a dedicated template service.
If you want, I can also show:
- a Node/Jinja/SendGrid example
- a best-practice repo structure
- or a dev/staging/prod email config pattern for your stack.