Skip to content

Instantly share code, notes, and snippets.

@viktorpetryk
Last active January 27, 2023 09:08
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save viktorpetryk/b7016104542597c98f711d436806ea25 to your computer and use it in GitHub Desktop.
Save viktorpetryk/b7016104542597c98f711d436806ea25 to your computer and use it in GitHub Desktop.
MailHog installation on Ubuntu

Install & Configure MailHog

  1. Download and make it executable
wget https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64
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
[Unit]
Description=Mailhog
After=network.target
[Service]
User=%user%
ExecStart=/usr/bin/env /usr/local/bin/mailhog > /dev/null 2>&1 &
[Install]
WantedBy=multi-user.target
EOL

systemctl daemon-reload
systemctl enable mailhog
  1. Configure php.ini file (for needed version)
sudo sed -i "s/;sendmail_path.*/sendmail_path='\/usr\/local\/bin\/mailhog sendmail magento-dev@example.com'/" /etc/php/7.0/apache2/php.ini
sudo sed -i "s/;sendmail_path.*/sendmail_path='\/usr\/local\/bin\/mailhog sendmail magento-dev@example.com'/" /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
http://localhost:8025/
  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
@timo002
Copy link

timo002 commented Jan 10, 2019

This is great, thanks. Helped me out to install Mailhog on a local ubuntu server. But the problem I now have is that my ubuntu server has nog GUI. So I need to access this on the server from my browser on my own PC. Any idea of how to do that?

@scoutman57
Copy link

This is great, thanks. Helped me out to install Mailhog on a local ubuntu server. But the problem I now have is that my ubuntu server has nog GUI. So I need to access this on the server from my browser on my own PC. Any idea of how to do that?

You would access it via http://{your_server_ip}}:8025

@k4mrul
Copy link

k4mrul commented Feb 25, 2020

I had to start mailhog service before enabling mailhog.
systemctl start mailhog

Thanks a lot for this

@fbeve
Copy link

fbeve commented May 18, 2020

Hello,
It does not work on Ubuntu server. even after installing Apache.
An idea what is wrong ?

XXX@mailhog:~$ systemctl status
● mailhog
State: degraded //(in red)
Jobs: 0 queued
Failed: 1 units // (in red)
Since: Mon 2020-05-18 10:52:30 UTC; 1h 44min ago
CGroup: /

Note: I installed apache2. I am using Ubuntu server 18

@com2
Copy link

com2 commented Jun 29, 2021

Not sure which version of Ubuntu is in mind here but here on my 18.04 LTS I got:

systemctl start mailhog
Failed to start mailhog.service: Unit mailhog.service is not loaded properly: Exec format error.
See system logs and 'systemctl status mailhog.service' for details.

And status says:

systemctl status mailhog.service
● mailhog.service - Mailhog
   Loaded: error (Reason: Exec format error)
   Active: inactive (dead)

Jun 29 10:06:29 hostname systemd[1]: /etc/systemd/system/mailhog.service:5: Invalid user/group name or numeric ID: rootser%

I changed User to root and added Group root and then it started. But then I see gibberish on the screen:

image

What is missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment