The Goal

Learn how to install the MailHog SMTP server and configure the MODX mail settings for local email testing.

Author
Name:
Profession: Web Design & Development
Specialties: Front-end development, hand-drawing
Years’ Experience: 17
Tutorial Details
Experience Level: Noob
Noob: No coding skills required.
Beginner: Entry-level coding skills.
Intermediate: Code literate.
Advanced: Code fluent. Extensive technical skills.
Über Geek: Need I say more?
Tools: MailHog, Homebrew, MODX, Terminal
Completion Time: 15-30 minutes
Related Article: Source
Tags: mailhog, email, modx, homebrew

This is a member-contributed tutorial. If possible, contact the author with questions or comments.

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.

There are more feature-rich alternatives like Mailtrap which 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

  1. Sign-in to the MODX Manager.
  2. Go to Menu > [ Cog ] > System Settings.
  3. 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.
  4. Leave SMTP Authentication set to the default No.
  5. Set SMTP Hosts to 127.0.0.1 or localhost.
  6. Set SMTP Port to 1025.
  7. Set Use SMTP to Yes.

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).

  1. 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)"
  2. Install MailHog:
    brew install mailhog
  3. Start MailHog:
    brew services start mailhog
  4. Launch MailHog:
    mailhog

That’s it. MailHog will now run in the background.

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.

Depending on the application the configuration process will vary.


Tutorials Archive show by year/month