Using Mailhog via Docker For Development

When you’re developing your application locally you might want to send emails to users of your system.

In development, you don’t want to be sending real emails as you might accidentally be sending development emails to real customers. You need a way of testing locally and make sure that no emails will be sent out to customers but still allow you to view all emails being sent out.

This is why mailhog was created, it’s a great development tool for testing emails and you can find the repository on Github.

You can run this locally on your machine by using the following commands

brew update && brew install mailhog

This will setup SMTP on port 1025 and allow you to see these emails on port 8025.

But not every project needs to have mailhog so you might not want this running all the time you can use docker to install mailhog instead to use it on the projects that actually need it.

Install With Docker

docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog

Now navigate to and you will see the mailhog interface.

To test this you can use telnet to submit a email.

telnet localhost 1025 EHLO 
Subject: Hello World
Hello World!

You should now be able to see a test email in your mailhog interface.

Install With Docker Compose

services: mailhog: image: mailhog/mailhog ports: - 1025:1025 - 8025:8025

Now when you run docker-compose up -d you will be able to see and use mailhog within this docker network.

This allows you to use Mailhog in any of your local development environments.

Originally published at

Software Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store