MailHog is a nice mail testing tool for developers.
Website: https://github.com/mailhog/MailHog
Download the latest release on your local machine
wget https://github.com/mailhog/MailHog/releases/download/v1.0.0/MailHog_linux_amd64 -O /path/to/mailhog
chmod +x /path/to/mailhog
Note: Change /path/to/mailhog
according to your needs
In your php.ini configuration file (called php.ini
),
search for the string sendmail_path
and replace it with the following:
sendmail_path = "/path/to/mailhog sendmail [email protected]"
Note: Change /path/to/mailhog
according to your needs
PHP configuration file path may vary according to your configuration. Here is some common places:
/etc/php/7.0/apache2/php.ini
/etc/php/7.0/fpm/php.ini
/etc/php5/apache2/php.ini
/etc/php5/fpm/php.ini
Place the following in a custom /etc/systemd/system/mailhog.service
file:
[Unit]
Description=MailHog Email Catcher
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/path/to/mailhog
StandardOutput=journal
Restart=on-failure
[Install]
WantedBy=multi-user.target
Note: Change /path/to/mailhog
according to your needs
Now you can enable and run your mailhog daemon
systemctl enable mailhog.service
systemctl start mailhog.service
Once started, you can acces MailHog web interface from http://localhost:8025, but who remembers ports number ?
To access MailHog from a nice url, for example http://mailhog.local, we must configure Apache as a reverse proxy.
Some Apache modules are needed, so enable it:
a2enmod vhost_alias proxy proxy_http proxy_wstunnel
In a /etc/apache2/sites-available/mailhog.conf
file, place the following configuration:
<VirtualHost 127.0.0.1:80>
# Name for your virtualhost
ServerName mailhog.local
# Proxy config
ProxyPreserveHost On
ProxyRequests Off
# Websocket proxy needs to be defined first
ProxyPass "/api/v2/websocket" ws://localhost:8025/api/v2/websocket
ProxyPassReverse "/api/v2/websocket" ws://localhost:8025/api/v2/websocket
# General proxy
ProxyPass / http://localhost:8025/
ProxyPassReverse / http://localhost:8025/
</VirtualHost>
Now enable your vhost and reload Apache
a2ensite mailhog.conf && apache2ctl graceful
Add the following line in your /etc/hosts
file:
127.0.0.1 mailhog.local
- http://iankent.uk/blog/introducing-go-mailhog/
- https://www.drupal.org/docs/develop/local-server-setup/managing-mail-handling-for-development-or-testing
- https://www.drupal.org/docs/develop/local-server-setup/managing-mail-handling-for-development-or-testing
- mailhog/MailHog#142 (comment)
- https://github.com/geerlingguy/drupal-vm/blob/master/provisioning/roles/geerlingguy.mailhog/templates/mailhog.unit.j2
@geoffreyvanwyk Thanks for putting this together. Do you know how to serve mailhog from a subpath?