Comment on page
Mailhog is similar to MailTrap in that it intercepts all email messages being sent from your application and displays them in a simple web interface. Mailhog is currently used by the Elentra Developer Docker environment to facilitate email testing by developers.
If you need to test features in Elentra that send out emails in your Development / Staging / Test environments, then the following instructions will help you install Mailhog on your servers.
To install Go, you will need to connect to your web server and execute the following commands:
sudo tar -C /usr/local -xzf go*.linux-amd64.tar.gz
Add the following line at the bottom of the
Save and exit the file. Refresh the path, exit out of superuser mode and verify that go is installed:
Run the following to install and run the Mailhog server:
go install github.com/mailhog/MailHog@latest
cp ~/go/bin/MailHog /usr/local/bin/Mailhog
You may need to exit out of your SSH connection, and then SSH back into the server before running Mailhog.
Leave Mailhog running from the command line until you have finished installing and testing
mhsendmailbelow. (Later we will add mailhog as a service that runs in the background automatically, so this is only needed temporarily.)
If the server is behind a load balancer, then you will either need to open up that port on the web server, or use the web server machine name instead of the URL above.
sendmailreplacement that will ensure that all emails are routed to Mailhog.
Clone and build
git clone https://github.com/mailhog/mhsendmail.git
go mod init
go get github.com/mailhog/mhsendmail/cmd
go mod vendor
sudo mv mhsendmail /usr/local/bin/mhsendmail
The current release tags of
v0.2.0and earlier) do not support the
mhsendmailis required to allow the
mhsendmail, you can copy and paste the following at the command prompt:
At this point you should be able to see this message in Mailhog in your web browser.
Next we need to make the system use
sendmail. (This is so we are sure that emails are sent to Mailhog and don't get out into the wild.)
On the web application server edit the
sudo vi php.ini
sendmail_path. Comment out the existing entry and add a new entry.
sendmail_path = "/usr/local/bin/mhsendmail -t --smtp-addr=localhost:1025"
Save and close the file. Restart the
supervisordservice, to reload
sudo systemctl restart supervisord
Elentra also uses the sendmail path specified in the
settings-xxx.inc.phpfiles. Change the
SENDMAIL_PATHconstant in the
settings-staging.inc.phpfile as follows.
define("SENDMAIL_PATH", "/usr/local/bin/mhsendmail -t -i --smtp-addr=localhost:1025");
Save the file, commit, then deploy the change.
Once you have Mailhog installed and Elentra pointed to it for sending mail, you will want to set up a Service to restart Mailhog when the server reboots.
If you have Mailhog manually running from the command line, you will want to exit out of it at this point.
Create a new Mailhog service:
sudo tee /etc/systemd/system/mailhog.service <<EOL
ExecStart=/usr/bin/env /usr/local/bin/Mailhog > /dev/null 2>&1 &
Start the service by issuing the following command.
sudo systemctl restart mailhog
To verify that the service is running, issue the following command.
sudo systemctl status mailhog