Introduction
MailHog is an email testing tool for developers that runs a local SMTP server and provides a web interface to view captured messages. Instead of configuring a real mail server or polluting inboxes during development, MailHog intercepts all outgoing emails so you can inspect content, headers, HTML rendering, and attachments in your browser.
What MailHog Does
- Runs a local SMTP server that accepts mail on a configurable port
- Stores captured messages in memory or on disk for inspection
- Provides a web UI to browse, search, and view emails with HTML preview
- Exposes a REST API for automated testing and CI integration
- Supports Jim (Chaos Monkey for SMTP) to simulate delivery failures
Architecture Overview
MailHog consists of three components: an SMTP server (MailHog-Server) that accepts incoming mail, a storage backend (in-memory, MongoDB, or Maildir), and a web UI plus API (MailHog-UI) served over HTTP. Messages flow from SMTP intake to storage, and the UI polls or streams updates via WebSocket. The modular design allows swapping storage backends without changing the SMTP layer.
Self-Hosting & Configuration
- Run as a single binary with no dependencies (download from GitHub releases)
- Deploy via Docker with port mapping for SMTP (1025) and web (8025)
- Configure storage backend with
-storage=mongodbor-storage=maildir - Set authentication on the web UI with
-auth-filefor shared environments - Use environment variables MH_SMTP_BIND_ADDR and MH_UI_BIND_ADDR for custom ports
Key Features
- Zero-config startup — single binary, no dependencies
- HTML email preview with source view and plain-text fallback
- REST API for querying messages in automated test suites
- Jim chaos mode simulates network failures and slow connections
- Supports SMTP AUTH and TLS for testing auth-enabled configurations
Comparison with Similar Tools
- Mailpit — Mailpit is a modern actively-maintained alternative with similar features and lower resource usage
- Mailtrap — Mailtrap is a cloud SaaS service; MailHog runs entirely locally with no account needed
- Papercut SMTP — Papercut is Windows-only; MailHog is cross-platform (Linux, macOS, Windows)
- LetterOpener (Ruby) — LetterOpener saves emails as files; MailHog provides a browsable web interface
- smtp4dev — smtp4dev is .NET-based; MailHog is a single Go binary with no runtime dependencies
FAQ
Q: Does MailHog actually send emails to recipients? A: No. MailHog captures and stores all messages locally. Nothing leaves your machine unless you explicitly configure release/forwarding.
Q: Can I use MailHog in CI pipelines? A: Yes. Start MailHog in Docker, point your test suite's SMTP config at it, and use the REST API to assert on captured messages.
Q: How do I persist emails across restarts?
A: Use -storage=maildir -maildir-path=/data to write messages to disk, or -storage=mongodb for a MongoDB backend.
Q: Is MailHog still maintained? A: MailHog receives limited updates. For active development, consider Mailpit which is a compatible successor with ongoing maintenance.