Skip to content

Testing Action Mailer Messages Locally

Alec Spottswood edited this page Mar 19, 2023 · 5 revisions

This guide will walk you through how to set up a MailDev server locally for use in ensuring email events are processed in Caseflow correctly.

Running the Local Email Server

In order to have emails from your development instance of Caseflow be sent to a Maildev inbox you only need to follow these two steps:

  1. In a terminal, run a maildev container:
docker run -p 1080:1080 -p 1025:1025 maildev/maildev
  • Keep this terminal open, or run the container with docker run -d to have it run detached in the background.
  1. Run the Caseflow backend with the WITH_TEST_EMAIL_SERVER environmental variable assignment prepending the typical make run-backend command:
WITH_TEST_EMAIL_SERVER=true make run-backend

That's it! You should now be able to observe email events that have occurred in Caseflow by navigating to http://localhost:1080/ in your web browser.

maildev-test

Tips

Creating an Alias to Start Maildev

For convenience, feel free to add the following line to your runtime config file (~/.bashrc or ~/.zshrc, most likely):

alias start-mail-server="docker run -p 1080:1080 -p 1025:1025 maildev/maildev"

Once you open a new terminal/run source ~/.<rc-file-name> you will be able to start Maildev with the start-mail-server command.

Testing Email Events Initiated in the Rails Console

Just like with the Caseflow backend, if you'd like to have the Rails Console send email messages to your local email server you will need to set the WITH_TEST_EMAIL_SERVER environmental variable prior to opening the console:

WITH_TEST_EMAIL_SERVER=true make c

Testing Email Events Triggered from Jobs

If you need to test email notifications that are being sent out via a job, you can spin up the respective Shoryuken queue with the appropriate make command:

WITH_TEST_EMAIL_SERVER=true make run-low-priority

Setting a Custom SMTP Port

If for whatever reason you require Maildev to listen on a different port than 1025, you can run the container with:

docker run -p 1080:1080 -p XXXX:1025 maildev/maildev

Where XXXX is your custom port.

To have the Caseflow backend utilize this port, you can set the TEST_MAIL_SERVER_PORT environmental variable:

WITH_TEST_EMAIL_SERVER=true TEST_MAIL_SERVER_PORT=XXXX make run-backend
Clone this wiki locally