MailHog is a simple package written in Go that acts as a mail server that captures all outbound email and puts it in a UI for you. Its GitHub repo is at https://github.com/mailhog/MailHog.
On Debian/Ubuntu systems, install the golang-go
package using apt.
On EL-based and other systems, follow the instructions at https://go.dev/doc/install
Once you’ve got Go installed, simply run the following commands:
go install github.com/mailhog/MailHog@latest
go install github.com/mailhog/mhsendmail@latest
When finished, you’ll have a MailHog
and mhsendmail
executable in your ~/go/bin
directory. I recommend copying the binaries over to /usr/sbin
.
If you’re running PHP and want to use it, change your sendmail_path
line in php.ini
to read the following:
sendmail_path=/usr/sbin/mhsendmail
Start MailHog by running /usr/sbin/MailHog &
You can now access the web UI at http://localhost:8025/

If you want MailHog to run automatically as a service, create this file as /etc/systemd/system/mailhog.service
[Unit]
Descripton=MailHog
After=network.target
[Service]
Type="Forking"
ExecStart=/usr/sbin/MailHog > /dev/null 2>&1 &
[Install]
WantedBy=multi-user.target
Then run systemctl enable mailhog
and systemctl start mailhog