Prompt
How do I set up a sandbox for testing email in development?
Latest observation
Nov 15, 2026
OpenAI APIWeb search: off
A good email sandbox lets you test sending mail in development without accidentally emailing real users.
Common options
1. Use a fake SMTP server locally
Good for local development and integration tests.
Popular tools:
- MailHog
- Mailpit
- smtp4dev
These run locally and capture outgoing email instead of delivering it.
Typical setup:
- Start the server
- Point your app’s SMTP settings to it
- Open the web UI to inspect messages
Example config:
SMTP_HOST=localhost
SMTP_PORT=1025
SMTP_USER=
SMTP_PASS=
SMTP_SECURE=false
2. Use a hosted email testing service
Good for shared dev/staging environments.
Popular services:
- Mailtrap
- Ethereal Email (good for testing, disposable inboxes)
- SendGrid sandbox mode if you already use SendGrid
These services accept messages but keep them out of real inboxes.
3. Disable delivery in non-production
If your app uses a real provider, add an environment-based switch:
- dev/test: send to sandbox or local capture server
- prod: send through the real provider
Example:
const isProd = process.env.NODE_ENV === "production";
const emailHost = isProd ? process.env.SMTP_HOST : "localhost";
Recommended setup
For most projects:
- Local dev: Mailpit or MailHog
- Shared QA/staging: Mailtrap or provider sandbox mode
- Production: real email provider
Best practices
- Never hardcode real credentials in source code
- Use environment variables
- Add a safety check to prevent real emails in dev/test
- Use a recognizable test recipient like
test@local.invalid - Log or preview email content in the sandbox UI
Example with Mailpit
If you use Docker:
services:
mailpit:
image: axllent/mailpit
ports:
- "1025:1025" # SMTP
- "8025:8025" # Web UI
Then set:
SMTP_HOST=localhost
SMTP_PORT=1025
Open:
- SMTP:
localhost:1025 - UI:
http://localhost:8025
If you want, I can give you a setup example for a specific stack like Node.js, Python/Django, Rails, or Docker Compose.