Prompt
How do I set up a sandbox for email development?
Latest observation
A good email-development sandbox lets you test sending, rendering, templates, and flows without emailing real users. The setup depends on how much realism you need, but here’s a solid approach.
1) Use a dedicated testing email service or sandbox
Pick one of these patterns:
Option A: Email-catching service
Services like:
- Mailtrap
- MailHog
- Ethereal Email (for Nodemailer)
- smtp4dev
These accept SMTP traffic and trap messages instead of delivering them. Good for:
- verifying templates
- checking headers/attachments
- testing send logic safely
Option B: Staging mailbox/domain
Set up:
- a staging SMTP provider account
- a test domain or subdomain like
mail-staging.example.com - a few internal test inboxes only
Good for:
- end-to-end provider integration
- DKIM/SPF/DMARC testing
- realistic deliverability checks
2) Separate config for dev/staging/prod
Use environment variables so your app never sends production mail from local/dev:
Example:
EMAIL_MODE=sandboxSMTP_HOST=...SMTP_USER=...SMTP_PASS=...FROM_EMAIL=dev@yourdomain.com
Make sure:
- production credentials are never in local
.env - dev/staging uses separate API keys
- the app blocks sending to non-test recipients in non-prod environments
3) Route all outbound email to safe recipients
Add safety guards such as:
- allowlist only
- rewrite recipients to a test inbox
- display a big warning banner in non-production emails
- reject external domains unless explicitly allowed
Example logic:
- if not prod, send only to
@yourcompany.comor a test mailbox - or replace
towithsandbox@yourcompany.com
4) Create a local mail viewer
If using a local SMTP catcher:
- run it in Docker or locally
- view sent emails in a web UI
- inspect:
- HTML
- plain text
- subject
- attachments
- links
- MIME structure
This is especially useful for template debugging.
5) Test rendering across clients
Email can look different in Gmail, Outlook, Apple Mail, etc. Use:
- Litmus
- Email on Acid
They help you test:
- responsive behavior
- dark mode
- Outlook quirks
- image blocking
- font fallbacks
6) Validate links, tracking, and attachments
In the sandbox, confirm:
- unsubscribe links work
- tracking parameters are correct
- images load from the right host
- attachments are the correct type/size
- link URLs point to staging, not production
7) Add seed data and scripted test cases
Create test users and data for common scenarios:
- welcome email
- password reset
- receipt/invoice
- notification
- error/fallback email
Automate checks where possible:
- snapshot tests for templates
- integration tests that confirm an email was “sent”
- assertions on subject/from/body content
8) Keep DNS/auth separate if testing deliverability
If you want realistic mail delivery:
- configure SPF, DKIM, DMARC for staging too
- use a subdomain like
staging.example.com - don’t mix staging and production sending identities
Simple recommended setup
If you want the easiest practical setup:
- Local development: MailHog or smtp4dev
- Staging: separate provider account + test domain/subdomain
- QA review: Litmus or Email on Acid
- Safety: allowlist recipients in non-prod environments
Example Docker-based local sandbox
If you want, I can give you a ready-to-run Docker Compose setup for:
- MailHog
- a sample SMTP config
- and app environment variables
If you tell me your stack (Node, Python, Rails, PHP, etc.), I can tailor the setup.