Prompt
How do I test transactional email in staging before it goes live?
Latest observation
To test transactional email safely in staging before production, use a setup that lets you verify content and delivery behavior without sending real customer emails.
Recommended approach
1. Use a separate email provider account or sandbox
Most email services offer a staging/sandbox mode:
- Mailgun: sandbox domains
- SendGrid: sandbox mode / suppressed sending
- SES: test environment with verified recipients and limited permissions
- Postmark: separate servers for staging and production
This lets staging send emails through a dedicated path that can’t accidentally hit real users.
2. Route staging emails to controlled inboxes
Configure staging so all outbound email goes to:
- your team’s test inboxes, or
- a catch-all mailbox like
staging-mail@yourcompany.com
You can also rewrite all recipients in staging to a single safe address.
3. Use a mail-catching tool
Instead of sending real email, point staging at a local or hosted capture inbox:
- MailHog
- Mailpit
- Papercut
- Ethereal Email
- Mailtrap
These let you inspect:
- subject/body
- HTML rendering
- attachments
- headers
- links
- tracking pixels
4. Gate by environment
Make sending behavior depend on environment variables:
APP_ENV=stagingEMAIL_MODE=sandboxEMAIL_REDIRECT_TO=test@yourcompany.com
In staging:
- disable production API keys
- use test keys
- turn off live webhooks if possible
- redirect all recipients
5. Verify templates and dynamic data
Test the actual transactional flows:
- signup confirmation
- password reset
- receipt/invoice
- notification emails
Check:
- personalization fields
- localization
- fallback values
- HTML + plain-text versions
- broken links
- unsubscribe headers if applicable
6. Test with seed data and edge cases
Create staging test users with:
- valid email
- invalid/odd names
- long names
- international characters
- missing optional fields
Also test edge cases:
- retry behavior
- duplicate sends
- bounced address handling
- suppressed/unsubscribed users
7. Prevent accidental production sends
Add safeguards:
- block sending unless recipient domain is allowlisted in staging
- force all emails to a test domain
- require a specific staging API key
- add a “dry run” mode
- log every outbound email in staging
Practical setup example
Staging
- Email provider: test/sandbox account
- All recipients rewritten to
qa@yourcompany.com - Real customer domains blocked
- Mail captured in Mailtrap/MailHog for inspection
Production
- Separate provider account/server
- Real sending enabled
- Webhooks and suppression lists active
Good testing checklist
- Email sends successfully from staging
- Correct subject and sender name
- Correct HTML and text body
- Links point to staging URLs
- Attachments render correctly
- No real customer gets emailed
- Bounce/retry behavior is understood
- Logs show message IDs and recipient rewrites
If you want, I can give you a concrete setup for a specific provider like SendGrid, SES, Mailgun, or Postmark, or show sample code for recipient rewriting in staging.