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.

Step-1

[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.

Step-2

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

Now Download and configure MailHog

Step-3

[email protected]:~# git clone https://github.com/mailhog/MailHog.git

[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 github.com/mailhog/MailHog

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

[email protected]:~# mailhog bcrypt [email protected]@123
$2a$04$Cqvq9D24HXeRtLR9DdgOKO5y3DHqpTm9dyPmX0laEP7Nv1r0Vq2Zy

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

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

support:$2a$04$Cqvq9D24HXeRtLR9DdgOKO5y3DHqpTm9dyPmX0laEP7Nv1r0Vq2Zy
(username:encryptedpassword)
..save


Starting MailHog automatically by adding a systemd service.

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

Step-4

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

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

[Unit]
Description=Start MailHog Service
After=network.target


[Service]
Type=forking
WorkingDirectory=/root/MailHog
ExecStart=/bin/sh -c "cd /root/MailHog; nohup mailhog -auth-file=/root/MailHog/docs/example-auth >> /var/log/mailhog.log 2>&1 &"
User=root
Group=root


[Install]
WantedBy=multi-user.target

 

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

Step-5

[email protected]:~# systemctl daemon-reload

[email protected]:~# systemctl enable mailhog
Created symlink from /etc/systemd/system/multi-user.target.wants/mailhog.service 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:

http://10.100.98.52:8025  (localhost IP:default_port)

 

install mailhog

Conclusion:

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.

Refresh