12

Using MailHog via Docker for testing email

 3 years ago
source link: https://akrabat.com/using-mailhog-via-docker-for-testing-email/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

I recently needed to modify the emails that a client project sends out. It was set up to send via SMTP and so the easiest way to do this for me was to add a local MailHog instance and point the application at it.

Manually running via Docker

The quickest and easiest way to do this is via Docker.

Manually, we can do:

$ docker run -p 8025:8025 -p 1025:1025 mailhog/mailhog

This will run MailHog with the SMTP port exposed on localhost port 1025 and the web interface on 8025.

Now you can configure the app’s SMTP config and away you go.

Test via telnet

You can test via telnet fairly easily if you have it installed:

$ telnet localhost 1025
EHLO 19ft.com
MAIL FROM:<[email protected]>
Subject: Hello World
Hello World!

Type each line out and press Enter between each one and you’ll see the new email in MailHog’s web interface:

Screenshot of MailHog

Docker compose

As I already had a Docker Compose setup for this project, I added the following to my docker-compose.yml:

services:
  mailhog:
    image: mailhog/mailhog
    logging:
      driver: 'none'  # disable saving logs
    ports:
      - 1025:1025 # smtp server
      - 8025:8025 # web ui

MailHog’s logs are quite chatty, so adding driver: 'none' to the logging section will turn them off if you don’t need them.

That’s it. I used to use Mailcatcher and still do on one project, but MailHog’s Docker container makes it much easier and quicker to set up.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK