Mailhog

Very similar to Mailtrap but means you can host internally. It also boasts a full Swagger based API from which a client library can be generated for your language of choice.

Written in Go, Mailhog acts as a local SMTP server and captures all emails without them reaching the true recipient (for testing purposes).

This means you can then use the API to perform test assertions around email sending in your application.

Set up

Docker

You can use Docker to get an instance up and running very quickly with a one liner.

1
docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog

Docker Compose

1
2
3
4
5
6
7
version: "3"
services:
  mailhog:
    image: mailhog/mailhog:latest
    ports:
      - 1025:1025
      - 8025:8025

Usage

For emails to be sent via Mailhog, you need to configure your application (or PHP) to use it as an SMTP server. By default, Mailhog listens on port 1025 for SMTP and port 8025 for the frontend dashboard and API.

When used with Docker/Compose, you can access both the SMTP and HTTP server by localhost with the specified port. E.g.

1
2
localhost:1025 #SMTP Server
localhost:8025 #HTTP Frontend

Mailhog Dashboard

Links

Mailhog Github Page