When we installed Go, we added a line to our profile to set the $GOPATH variable. This is the path where packages are installed. Let’s copy the above binaries to a location where they are available everywhere in the system:

Check out the above output: MailHog’s web interface is running at http://127.0.0.1:8025. Let’s open it in a browser:

Got it! MailHog is running. In the next section we will verify that it traps outgoing email and presents it in the web interface.

Note: MailHog listens by default on 0.0.0.0, which means all available network interfaces. This is the reason why we specify the loopback IP address when running the command as otherwise anyone connected to the same network than us could access to MailHog’s resources.

Testing email submission

The following command line script will send a dummy email using your existing PHP configuration:

Now let’s once again open MailHog’s web interface to verify that the email is there:

It worked! See, the web interface looks like an actual email client. There is also an API available which is useful if you want to run tests that check that email has been submitted. For example, the following request returns the list of email messages as a JSON string:

Start MailHog when the system boots

So we are all set but, what about tomorrow when I start my computer? Now that I know how MailHog works, I would like to keep it running all the time so I don’t need to worry about outgoing email while developing.

Linux supports systemd, a service manager. After some research, I found out that it is a common method to manage services. Let’s create a service file for MailHog and then register it.

Create the file /etc/systemd/system/mailhog.service and paste the following into it:

Finally run again the above PHP script to send a dummy email and verify that it comes up at the web interface.

You are done! From now on you won’t have to worry about outgoing email being sent from your local development environment. Plus, if you ever need to test outgoing email, you can now browse it at MailHog’s web interface or test it via making a request to its API.