Elentra Platform Technical Documentation
  • Introduction
  • Reporting Issues
    • Security Notices
  • Administrators
    • Server Requirements
    • Application Server
      • Shibboleth Single Sign-on
      • Installing Supervisor
      • Branded API Setup
      • Installing Mailhog
    • Database Server
  • Developers
    • Getting Started
    • Overview
    • Contributions
      • Request for Change
      • Jira and GitHub Details
      • Coding Standards
      • Quickstart Guide
      • Code Review
    • Database
    • Dataviews for Analytics
    • Global Namespace
    • Elentra ACL
    • Authentication Methods
    • Compatibility Matrix
    • Elentra ME Versions
    • Elentra Settings
    • Elentra Deployment
    • Elentra API
    • Elentra JS
    • Feature Configuration
      • Event Resource Integration
      • Microsoft Teams Integration
    • Troubleshooting & Guides
      • New developer features in Elentra ME 1.22
      • Testing With Codeception
        • Unit Testing
          • Unit Testing Best Practises
          • Writing Unit Testable Code
          • PHPUnit Testing for API
          • PHPUnit Json String Compare Function
        • Functional Testing
          • Functional Testing Best Practices
        • Integration Testing
          • Integration Testing Best Practices
      • Upgrading elentra-developer Docker
      • VS Code Setup
      • Using XDebug in VSCode
      • Upgrading PHP
      • Switching Databases
      • Creating a new virtual host
      • Logging In
      • Composer
      • Curriculum Tag Selector
      • Performance Issues
      • Docker
      • Seed Data Generation
      • Fail Fast Programming
      • Advanced Custom Exception Classes
    • Support
  • Upgrade Guides
    • Upgrading to ME v28.0
    • Upgrading to ME 1.27
    • Upgrading to ME 1.26
    • Upgrading to ME 1.25
    • Upgrading to ME 1.24
    • Upgrading to ME 1.23
    • Upgrading to ME 1.22
    • Upgrading to ME 1.21
    • Upgrading to ME 1.20
    • Upgrading to ME 1.19
    • Upgrading to ME 1.18
    • Upgrading to ME 1.17
    • Upgrading to ME 1.16
    • Upgrading to ME 1.15
Powered by GitBook
On this page
  • Install Go
  • Install Mailhog
  • Install mhsendmail
  • Replace sendmail with mhsendmail
  • Update php.ini
  • Update sendmail path in settings file
  • Set up Mailhog as a Service
  1. Administrators
  2. Application Server

Installing Mailhog

PreviousBranded API SetupNextDatabase Server

Last updated 1 year ago

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.

Install Go

To install Go, you will need to connect to your web server and execute the following commands:

wget https://go.dev/dl/go1.21.1.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go*.linux-amd64.tar.gz
vi /etc/profile

Add the following line at the bottom of the /etc/profile file.

export PATH=$PATH:/usr/local/go/bin

Save and exit the file. Refresh the path, exit out of superuser mode and verify that go is installed:

source /etc/profile
go version

Reference:

Install Mailhog

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
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 mhsendmail below. (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.

Install mhsendmail

mhsendmail is a sendmail replacement that will ensure that all emails are routed to Mailhog.

Clone and build mhsendmail:

git clone https://github.com/mailhog/mhsendmail.git
cd mhsendmail
go mod init
go get github.com/mailhog/mhsendmail/cmd
go mod vendor
go build
sudo mv mhsendmail /usr/local/bin/mhsendmail

The current release tags of mhsendmail (v0.2.0 and earlier) do not support the -t flag. The master branch of mhsendmail is required to allow the -t flag.

To test mhsendmail, you can copy and paste the following at the command prompt:

mhsendmail -t test@mailhog.local <<EOF
From: App <app@mailhog.local>
To: Test <test@mailhog.local>
Subject: Test message
 
Some content!
EOF

At this point you should be able to see this message in Mailhog in your web browser.

Replace sendmail with mhsendmail

Next we need to make the system use mhsendmail instead of sendmail. (This is so we are sure that emails are sent to Mailhog and don't get out into the wild.)

Update php.ini

On the web application server edit the php.ini file.

cd /etc/
sudo vi php.ini

Search for 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 supervisord service, to reload php.ini:

sudo systemctl restart supervisord

Update sendmail path in settings file

Elentra also uses the sendmail path specified in the settings-xxx.inc.php files. Change the SENDMAIL_PATH constant in the settings-staging.inc.php file as follows.

define("SENDMAIL_PATH", "/usr/local/bin/mhsendmail -t -i --smtp-addr=localhost:1025");

Save the file, commit, then deploy the change.

Set up Mailhog as a Service

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
[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

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

To access the Mailhog interface, use your browser to navigate to port 8025 on the web server. e.g.

Reference:

Reference:

Reference:

Reference:

Mailhog
computingforgeeks.com
http://staging.elentra.med.university.edu:8025
gist
mailtrap.io
gist
gist