Skip to content

Instantly share code, notes, and snippets.

@renatomefi
Last active December 13, 2021 12:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatomefi/d133fea9cb5a7b00f91edb24b83d9a31 to your computer and use it in GitHub Desktop.
Save renatomefi/d133fea9cb5a7b00f91edb24b83d9a31 to your computer and use it in GitHub Desktop.
Milhog start script for Ubuntu 14.04

This is a simple way to install mailhog, might not be the best solution for everyone, you can look for repositories, still have to register the binary in the PATH, among other things, this is a manual simple install.

Binary download

Download mailhog from the releases page on github: https://github.com/mailhog/MailHog/releases Save the binary at /opt/mailhog/mailhog Give it executable permission chmod +x /opt/mailhog/mailhog

Init script

Download the gist: https://gist.github.com/renatomefi/d133fea9cb5a7b00f91edb24b83d9a31#file-init-d-mailhog-sh Put it at /etc/init.d/mailhog Give it executable permission chmod +x /etc/init.d/mailhog Register it to system startup: update-rc.d mailhog defaults

Protect it with password: Generate a password using /opt/mailhog/mailhog bcrypt MySuperPassword output: $2a$04$BqpzxoGr2TfYdYiOeH1OjO9mSKeTzisJDgcDKIWNBNHgDWlijCOiC Create a file /opt/mailhog/auth with the content:

myusername:$2a$04$BqpzxoGr2TfYdYiOeH1OjO9mSKeTzisJDgcDKIWNBNHgDWlijCOiC

Open in the browser the ip of the machine on the port 8025, i.e.: http://localhost:8025

Optional nginx configuration

If you want to serve mailhog on a shared web server you can do something like in your nginx default file: /etc/nginx/sites-enabled/default

   location /mailhog/ {
     proxy_pass http://127.0.0.1:8025/;
     proxy_set_header Host $host;

     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
   }

Or if you have a hostname you can go for a new vhost config: /etc/nginx/sites-enabled/mailhog

server {
   listen 80;

   server_name localhost;
   location /mailhog/ {
     proxy_pass http://127.0.0.1:8025/;
     proxy_set_header Host $host;

     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
   }
}

#! /bin/sh
# /etc/init.d/mailhog
#
# MailHog init script.
#
# @author Jeff Geerling
# @author Renato Mendes Figueiredo
### BEGIN INIT INFO
# Provides: mailhog
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start MailHog at boot time.
# Description: Enable MailHog.
### END INIT INFO
PID=/var/run/mailhog.pid
USER=nobody
MAILHOG_PATH=/opt/mailhog
BIN=$MAILHOG_PATH/mailhog
MAILHOG_OPTS="-auth-file=$MAILHOG_PATH/auth -api-bind-addr=0.0.0.0:8025 -ui-bind-addr=0.0.0.0:8025"
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting mailhog."
start-stop-daemon --start --pidfile $PID --make-pidfile --user $USER --background --exec $BIN -- $MAILHOG_OPTS
;;
stop)
if [ -f $PID ]; then
echo "Stopping mailhog.";
start-stop-daemon --stop --pidfile $PID
else
echo "MailHog is not running.";
fi
;;
restart)
echo "Restarting mailhog."
start-stop-daemon --stop --pidfile $PID
start-stop-daemon --start --pidfile $PID --make-pidfile --user $USER --background --exec $BIN -- $MAILHOG_OPTS
;;
status)
if [ -f $PID ]; then
echo "MailHog is running.";
else
echo "MailHog is not running.";
exit 3
fi
;;
*)
echo "Usage: /etc/init.d/mailhog {start|stop|status|restart}"
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment