Install mailhog on ubuntu 16.04

(Last Updated On: October 24, 2019)

Install mailhog on ubuntu 16.04


MailHog is a tool used by developers for testing emails. Generally, we install mailhog because it is a very lightweight and portable application that acts exactly like an SMTP server.

It was originally written in Perl before, but it has been rewritten in Go, which is essential for portability. It has been designed for testing emails during application development.

At first, update and upgrade the repository before you install mailhog.


[email protected]:~# apt-get update
[email protected]:~# apt-get upgrade

MailHog is written in Go, So we need to install the “golang” (Go Language). Only if it is not installed already.


[email protected]:~# apt-get -y install golang-go
[email protected]:~# pwd

Now Download and configure MailHog


[email protected]:~# git clone

[email protected]:~# cd MailHog/

[email protected]:~/MailHog# mkdir gocode

[email protected]:~/MailHog# cd gocode/

[email protected]:~/MailHog/gocode# vi ~/.profile

export GOPATH=/root/MailHog/gocode    (add this line at the end)
-- save.

[email protected]:~/MailHog/gocode# source ~/.profile 

[email protected]:~/MailHog/gocode# go get

[email protected]:~/MailHog/gocode# cp -Rap bin/MailHog /usr/local/bin/mailhog

[email protected]:~# mailhog bcrypt [email protected]@123

[email protected]:~/MailHog/gocode# cd ../docs/

[email protected]:~/MailHog/docs# vi example-auth


Starting MailHog automatically by adding a systemd service.

Note: edit the file and add the below script. Also, change the path accordingly (ExecStart).


[email protected]:~/MailHog/docs# cd ~ 

[email protected]:~# vi /etc/systemd/system/mailhog.service

Description=Start MailHog Service

ExecStart=/bin/sh -c "cd /root/MailHog; nohup mailhog -auth-file=/root/MailHog/docs/example-auth >> /var/log/mailhog.log 2>&1 &"



Now reload the systemd daemon, so that the changes get effected.


[email protected]:~# systemctl daemon-reload

[email protected]:~# systemctl enable mailhog
Created symlink from /etc/systemd/system/ to /etc/systemd/system/mailhog.service.

[email protected]:~# systemctl start mailhog

[email protected]:~#  systemctl status mailhog

mailhog.service - Start MailHog Service
  Loaded: loaded (/etc/systemd/system/mailhog.service; enabled; vendor preset: enabled)
  Active: active (running) since Mon 2019-10-21 18:29:17 IST; 8s ago
  Process: 7147 ExecStart=/bin/sh -c cd /root/MailHog; nohup mailhog -auth-file=/root/MailHog/docs/example-auth >> /var/log/mailhog.lo
  Main PID: 7148 (mailhog)
  Tasks: 3
  Memory: 1.7M
  CPU: 11ms
   CGroup: /system.slice/mailhog.service
           └─7148 mailhog -auth-file=/root/MailHog/docs/example-auth


Note: In case, if you want to run it manually without adding a systemd service for automatic startup. Then you can run the below command.

[email protected]:~# mailhog -auth-file=/root/MailHog/docs/example-auth


  • Now check it from browser:  (localhost IP:default_port)


install mailhog


With this piece of article, I have tried my best to simplify the installation and configuration of MailHog. By following these steps you can easily install MailHog and use it.

Now I am expecting your responses. If you like this content or even dislike,  just leave a comment. Your responses will motivate me to do better and deliver better. I will try my best to enrich my skills.

So thank you guys, Have a good day.



Rate this content

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Ad Blocker Detected

Ad Blocker Detected, please disable it to help this page in many ways. Thank you so much.