Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
MailHog installation on Ubuntu

Install & Configure MailHog

  1. Download and make it executable
sudo cp MailHog_linux_amd64 /usr/local/bin/mailhog
sudo chmod +x /usr/local/bin/mailhog
  1. Make MailHog as a service

%user% = your username in the system

sudo tee /etc/systemd/system/mailhog.service <<EOL
ExecStart=/usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 &

systemctl daemon-reload
systemctl start mailhog
systemctl enable mailhog
  1. Configure php.ini file (for needed version)
sudo sed -i "s/;sendmail_path.*/sendmail_path='\/usr\/local\/bin\/mailhog sendmail'/" /etc/php/7.0/apache2/php.ini
sudo sed -i "s/;sendmail_path.*/sendmail_path='\/usr\/local\/bin\/mailhog sendmail'/" /etc/php/7.1/apache2/php.ini
  1. Restart Apache to apply changes in php.ini file.
sudo service apache2 restart
  1. Open url in browser
  1. When any php script send an email, it will be catched by MailHog and you can read it in the UI.

  2. Configuring MailHog

Add to your .bashrc

# Set message storage: memory | mongodb | maildir
export MH_STORAGE=maildir
  1. Install postfix and mailutils
sudo apt install postfix mailutils

Select "Internet Site" Use the default name and press Enter

  1. Edit main postfix file Edit /etc/postfix/

myhostname = localhost
relayhost = [localhost]:1025
default_transport = smtp

sudo postfix restart
sudo postfix reload
  1. Test
echo "Test Email message body" | mail -s "Email subject" kamrul@kamrul.local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.