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 (and 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 application/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).
- 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
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.
The MailHog GitHub site has additional configuration options depending on your choice of installation.
A Security Note About mhsendmail
mhsendmail
is a sendmail
replacement for MailHog that ensures mail is sent through the localhost:1025
IMAP server. It’s probably a good idea to determine if it’s necessary for your project.
My guess is that it will depend in part on the application you’re using. 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. But if you have experience with such things and feel this is incorrect then please let me know so I can update this post.
1 Depending on the application the configuration process will vary.