Using Mailpit for Local E-Mail Testing
Recently, I needed to test a web application that sends emails after various events—things like users registrations, password resets, and notifications triggered by user actions. It is quite cumbersome to set up different mail accounts and make sure to receive the emails, especially when all you have is a mail terminal program.
When asking for help and ideas for testing, I got the advice to overwrite the SMTP settings of my backend development server. So I did a quick search for an SMTP server for development and found out about Mailpit.
Getting Started
Since I’m on a Mac, I installed Mailpit using Homebrew:
brew install mailpit
The install was quick and painless. No dependencies, no config files—just a single binary ready to go.
Running Mailpit
To get started, I just ran:
mailpit
By default, Mailpit listens for SMTP connections on port 1025
and serves a web UI at http://localhost:8025. The terminal output confirmed both were up and running.
Pointing My App to Mailpit
My web app uses Pocketbase for sending emails. All I had to do was update the SMTP settings to point to localhost:1025
.
For testing, I did that directly in the Admin UI of Pocketbase. However, after saving a server-side script, the SMTP settings were reset. So I would recommend creating a settings script instead.
But for testing, in most cases, this is just fine.
No authentication is needed; however, I did change the TLS check to AutoTLS under Show more options
, otherwise errors in this regard would occur.
Testing the Flow
With Mailpit running, I triggered a few actions in my app that would normally send emails. Sure enough, every message appeared instantly in the Mailpit web UI. The interface is clean and makes it easy to inspect the email content, recipients, and headers. I could quickly verify that the right emails were being sent at the right times, and check for formatting or content issues.
Final Impressions
Mailpit turned out to be exactly what I needed: a simple, reliable way to catch and review emails during development. I’ll definitely keep it in my toolkit for future projects.
If you’re working on anything that sends email, I recommend giving it a try—it’s a small step that can save a lot of headaches down the road.
Thanks for reading. See you next time!
~ jacky