MODX + MailHog
MailHog, like MailCatcher which inspired it (see my tutorial) is a very simple but useful mail testing tool created by Ian Kent. It functions as a local SMTP server with a basic GUI for email testing and debugging which, no surprise here, is useful for Web application development.
Are there more feature-rich alternatives? Sure. Mailtrap is a commercial (online) option but for my needs I find MailHog (or MailCatcher) ideal, though your mileage may vary. For the purpose of this tutorial I’ll show you how to configure MailHog for use with MODX but it could be used with other Web applications/CMS1.
MODX Mail Configuration
- Sign-in to the MODX Manager.
- Go to Menu > [ Cog ] > System Settings.
- Leave the picker at the default core setting and in the Filter by area... picker select Mail. You should see 13 Mail settings. We’re only concerned with 4 of them.
- Leave
SMTP Authentication
set to the defaultNo
. - Set
SMTP Hosts
to127.0.0.1
orlocalhost
. - Set
SMTP Port
to1025
. - Set
Use SMTP
toYes
.
Installing MailHog
On its Github page it states “MailHog runs without installation” but you still need to download it and that can be done a few different ways: GitHub, Docker, Compose, Homebrew or Golang. For the purpose of this tutorial I used Homebrew (Mac and Linux). The MailHog GitHub site has additional configuration options depending on your choice of installation.
For those new to using the Terminal or command-line, after typing or copying/pasting a command hit Return then wait for the next prompt before entering the next command.
- Using the Terminal/command-line install Homebrew (Mac and Linux) if you haven’t already:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install MailHog:
brew install mailhog
- Start MailHog:
brew services start mailhog
- Launch MailHog:
mailhog
* To (re)start MailHog repeat Step 4.
Going Whole (Mail)Hog
MailHog should now be accessible at http://localhost:8025 in your browser. If you configured the mail settings correctly when you send emails through your local MODX-built site they should instantly appear in the MailHog GUI.
A Security Note About mhsendmail
mhsendmail
is a sendmail
replacement for MailHog that ensures mail is redirected to MailHog using SMTP. The GitHub page has additional information. As it applies to MODX since the SMTP Hosts
and SMTP Port
have been explicitly set in System Settings > Core > Mail then my guess is we are probably ok security-wise.
1 Depending on the application the configuration process will vary.