Skip to content
freeCodeCamp.org

Catching emails locally

Introduction

Some email workflows, like updating a user’s email, require the back-end API server to send outgoing emails. MailHog is an alternative to using an email service provider to send actual email messages. It is a developer tool for email testing that will catch the email messages sent by your freeCodeCamp instance.

Installing MailHog

MailHog can be installed on macOS, Windows, and Linux or used via Docker.

Installing MailHog with Docker

If you have Docker installed then you can use

Terminal window
docker run --name mailhog -d -e "MH_STORAGE=maildir" -v $PWD/maildir:/maildir -p 1025:1025 -p 8025:8025 mailhog/mailhog

to start MailHog in the background and

Terminal window
docker stop mailhog

to stop it.

When the installation completes, you can start using MailHog.

Installing MailHog on macOS

Install MailHog on macOS with Homebrew:

Terminal window
brew install mailhog
brew services start mailhog

The above commands will start a MailHog service in the background.

When the installation completes, you can start using MailHog.

Installing MailHog on Windows

Download the latest version of MailHog from MailHog’s official repository. Locate and click on the link for your Windows version (32 or 64 bit) and a .exe file will be downloaded to your computer.

When the download completes, click to open the file. A Windows firewall notification may appear, requesting access permission for MailHog. A standard Windows command line prompt will open where MailHog will be running once firewall access is granted.

Close MailHog by closing the command prompt window. To start MailHog again, click on the MailHog executable (.exe) file that was downloaded initially - it is not necessary to download a new MailHog installation file.

Start using MailHog.

Installing MailHog on Linux

First, install Go.

Run the following commands to install GO on Debian-based systems like Ubuntu and Linux Mint.

Terminal window
sudo apt-get install golang

Run the following commands to install GO on RPM-based systems like CentOS, Fedora, Red Hat Linux, etc.

Terminal window
sudo dnf install golang

Alternatively, run the following commands to install GO.

Terminal window
sudo yum install golang

Now set the path for Go with the following commands.

Terminal window
echo "export GOPATH=$HOME/go" >> ~/.profile
echo 'export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin' >> ~/.profile
source ~/.profile

Finally, enter the commands below to install and run MailHog.

Terminal window
go get github.com/mailhog/MailHog
sudo cp /home/$(whoami)/go/bin/MailHog /usr/local/bin/mailhog
mailhog

Start using MailHog.

Using MailHog

Open a new browser tab or window and navigate to http://localhost:8025 to open your MailHog inbox when the MailHog installation has been completed and MailHog is running.

  • Check out the MailHog repository for further information related to MailHog. Additional information is also available regarding custom MailHog configurations.