Skip to content

Instantly share code, notes, and snippets.

@paveli
Last active September 18, 2023 08:10
Show Gist options
  • Save paveli/65cc6409e60d337c64e34895c0bbe0f5 to your computer and use it in GitHub Desktop.
Save paveli/65cc6409e60d337c64e34895c0bbe0f5 to your computer and use it in GitHub Desktop.
MailHog configuration on Ubuntu Server
#!/usr/bin/env bash
#
# This shell script automates installation of MailHog on Ubuntu Server for PHP development enviroment
# Tested with Ubuntu 14.04 LTS
# Run with root privileges ($ sudo -s)
#
# Get MailHog binary and place it to /usr/local/bin/mailhog
wget -nv -O /usr/local/bin/mailhog https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64
chmod +x /usr/local/bin/mailhog
# Configure Mailhog to run as a daemon
apt-get install -y daemon
cp mailhog-init.d.config /etc/init.d/mailhog
chmod +x /etc/init.d/mailhog
/etc/init.d/mailhog start
apt-get install -y sysv-rc-conf
sysv-rc-conf mailhog on
# Get and install mhsendmail
apt-get install -y git
apt-get install -y golang
export GOPATH="$HOME/go"
go get github.com/mailhog/mhsendmail
cp ~/go/bin/mhsendmail /usr/local/bin/mhsendmail
# Configure PHP to work with mhsendmail
cat php-mailhog.config >> /etc/php5/apache2/php.ini
#! /bin/sh
# /etc/init.d/mailhog
#
# MailHog init script.
#
# @author Jeff Geerling
### 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
LOCK=/var/lock/mailhog.lock
USER=root
BIN=/usr/local/bin/mailhog
DAEMONIZE_BIN=/usr/bin/daemon
# BIND="-ui-bind-addr=127.0.0.1:8025 -api-bind-addr=127.0.0.1:8025"
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting mailhog."
$DAEMONIZE_BIN -F $PID -l $LOCK -u $USER -X $BIN
;;
stop)
if [ -f $PID ]; then
echo "Stopping mailhog.";
kill -TERM $(cat $PID);
rm -f $PID;
else
echo "MailHog is not running.";
fi
;;
restart)
echo "Restarting mailhog."
if [ -f $PID ]; then
kill -TERM $(cat $PID);
rm -f $PID;
fi
$DAEMONIZE_BIN -F $PID -l $LOCK -u $USER $BIN
;;
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
[MailHog]
sendmail_path = /usr/local/bin/mhsendmail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment