Prompt
How do I test emails locally without sending to real users?
Latest observation
The easiest way is to use a local email testing tool instead of a real SMTP provider. That lets your app “send” emails, but they get captured in a local inbox or log.
Good options
1. MailHog
A popular local email catcher.
- Runs locally with Docker or as a binary
- Exposes an SMTP server your app sends to
- Shows captured emails in a web UI
Typical setup
- SMTP:
localhost:1025 - Web UI:
http://localhost:8025
Example Docker:
docker run -p 1025:1025 -p 8025:8025 mailhog/mailhog
Then configure your app’s SMTP settings to point to localhost:1025.
2. Mailpit
A modern alternative to MailHog.
- Similar local SMTP capture
- Nice web UI
- Good for development and testing
Example Docker:
docker run -p 1025:1025 -p 8025:8025 axllent/mailpit
Web UI is usually at:
http://localhost:8025
3. Fake SMTP server / test server in code
Useful for automated tests.
For example:
- In Node.js, use a mock SMTP library
- In Python, use a local test server or monkeypatch your mail client
- In Ruby, use a test delivery adapter
This is best for unit/integration tests where you want to assert:
- an email was “sent”
- subject/body are correct
- recipient addresses are correct
4. Use a real provider’s sandbox/testing mode
Some email services offer a test mode or sandbox, such as:
- SendGrid
- Mailgun
- Amazon SES
These can let you validate sending logic without delivering to real users.
Recommended approach
For local development:
- Use Mailpit or MailHog
- Point your app’s SMTP configuration at the local catcher
- Inspect emails in the web UI
For automated tests:
- Mock the email-sending layer or use a fake SMTP server
- Verify the email content and count
Important safety tips
- Never point development environments at production SMTP credentials
- Use separate config files or environment variables for local/dev/prod
- Make it very obvious when emails are going to real recipients
If you want, I can show you a setup example for your stack, like Node.js, Python/Django, Rails, or Java/Spring.