Prompt
How do I test email sending safely in staging without emailing real users?
Latest observation
Nov 18, 2026
OpenAI APIWeb search: off
A safe way to test email in staging is to make sure all outbound mail is intercepted or rerouted before it can reach the real internet. Good options:
Best practices
-
Use a mail catcher / sink
- Route staging SMTP to a tool like:
- Mailpit
- MailHog
- Papercut
- MailCatcher
- These accept emails and show them in a local web UI instead of delivering them.
- Route staging SMTP to a tool like:
-
Use a test SMTP account with restricted recipients
- If you must use a real provider, create a staging-only account/API key.
- Configure it to:
- allow only approved test addresses
- reject or rewrite any other recipient
- Some providers support sandbox modes.
-
Rewrite recipients in staging
- Force all outgoing mail to a single inbox like
qa@yourcompany.com. - Preserve the original recipient in the subject/body or headers for debugging.
- Force all outgoing mail to a single inbox like
-
Block real delivery at the network level
- In staging, disallow outbound SMTP/HTTP email provider calls except to your mail catcher or test provider.
- This adds a safety net if app config is wrong.
-
Use environment-based guards
- Add hard checks such as:
- only send if
ENV=productionORALLOW_EMAIL=true - otherwise drop, redirect, or log
- only send if
- Avoid relying only on “we won’t click that button.”
- Add hard checks such as:
-
Make staging data fake
- Ensure staging user records contain fake domains like:
example.comtest.invalid
- Use seeded test inboxes if you need end-to-end flows.
- Ensure staging user records contain fake domains like:
Common safe patterns
- Mailpit + SMTP relay for local/staging preview
- Provider sandbox mode for API-based sending
- Recipient override to a single QA mailbox
- Dual protection: app-level guard + network block
What to avoid
- Using real production SMTP credentials in staging
- Sending to real customer emails “just for a quick test”
- Relying only on manual discipline without technical safeguards
A solid setup
For most teams:
- Staging app sends mail to Mailpit
- Network blocks any other outbound email destinations
- A config flag like
EMAIL_DELIVERY_MODE=catch-all - Optionally preserve original recipient in headers for debugging
If you want, I can show you a sample configuration for Mailpit, SendGrid sandbox, SES sandbox, or Postfix recipient rewriting depending on your stack.