For every project we need email functionality for, be it transactional or inbound, we choose Mailgun as our service provider. Over the years we tried different services but found this one to serve our every need. They have excellent support, a pretty neat dashboard and decent logging. For the most part, it has everything we need - except for the occasional noisy senders on our shared IPs.
There is only one small downside: data retention is expensive. We do not need it very often, but when we do encounter a bug or an email that seemingly didn’t arrive, three days just isn’t enough. Sometimes we just want to look back a week and see the chain of events linked to a specific email.
To tackle this problem we decided to build a very simple Phoenix application that stores and archives events from Mailgun. Through their API, we regularly fetch all events from a Mailgun account in a Postgres db. This allows use to go back for weeks or months and search for activity by email, event type, subject or other parameters. The application can have multiple Mailgun domains/accounts linked across the US and EU API.
The application has very minimal styling and the following pages:
It also features a minimal search. We kept this dead easy by design since we have no intention to recreate the excellent interface Mailgun offers us. All we wanted was to be able to go back further and know wether an email got deliver or not.
You can run this locally or set it up very easily on a small VPS using the Docker image.
With the following
version: "3" services: db: image: postgres networks: - webnet environment: POSTGRES_PASSWORD: logger POSTGRES_USER: logger POSTGRES_DB: mailgun_logger web: image: jackjoe/mailgun_logger ports: - "5050:5050" networks: - webnet environment: DB_HOST: db ML_DB_USER: logger ML_DB_PASSWORD: logger ML_DB_NAME: mailgun_logger ML_DB_HOST: db networks: webnet:
$ docker-compose up
Then head over to http://0.0.0.0:5050.
The full source code, instructions and a ready to use Docker image can be found in the source code and readme over at Github.