Drag
5-Step Mailpit Configuration for Offline Email Testing 5-Step Mailpit Configuration for Offline Email Testing
Sundew
Author Sundew
Date December 3rd, 2024
Time to Read 5 min.
Technology

5-Step Mailpit Configuration for Offline Email Testing

by Sundew

There are several ways to test and debug SMTP emails. The most common method is to use an online service like Mailtrap or Mailgun. While these tools are incredibly useful, they often come with a cost and require an internet connection, leading to resource constraints, especially with the free tiers.

Developers often find themselves sending email notifications frequently to test different functionalities. In the search for efficient and cost-effective solutions, professionals often look for alternatives that could be used offline. 

Among these are two offline-based software options for testing emails locally: Helo (Paid) and Mailpit (Free | Open Source). Given that Mailpit is free and open-source, it is a go-to tool for many. In this blog, get familiar with how to install and configure Mailpit, making email testing both accessible and efficient.

How to Use Mailpit for Offline Email Testing?

If you’re wondering how to set up Mailpit, the following steps can help you get started.

Step 1 - Download Mailpit

Follow the install instructions here:

GitHub - axllent/mailpit: An email and SMTP testing tool with API for developers

For windows you can check the releases page. There can be multiple variants, namely AMD, ARM and x386. You would need to download the file based on your OS and processor type.

  • AMD/AMD64 - For Intel/AMD processors
  • ARM - ARM processor (mostly found in mobile devices)
  • x386 - 32-bit Intel processors

Step 2 - Install Mailpit

While installing on Linux is easy, there are a few more steps to follow on Windows.

Once the zip file is downloaded, extract it to a location as per your choice. The extracted contents will look like this:

Install Mailpit

Step 3 - Add mailpit path to environment

To add the mailpit path to environment $PATH variable, follow these steps:

3.1. Search for env

Search for env

3.2. Click on the control panel item. It will open this window. Then click on the highlighted button. 

System Properties

3.3. You may choose to modify either the user or system variables. Select path and then click on edit according to your selection.

Select Path

3.4. In the newly opened window, click on New and add mailpit installation path like the following.

Edit Environment Variable

3.5. Click OK → OK → Apply → OK.

Step 4 - Using persistent storage

All email data will be lost once mailpit closes. To mitigate this, we can use a sqlite database.

Just create a blank file but make sure to keep its extension as .sqlite

You can keep the file anywhere on your system but it is suggested to create the file in the installation folder.

Step 5 - Launch Mailpit

Run the following command in your terminal to launch Mailpit with persistent storage.

mailpit -d "<DB_PATH>" -v

Replace <DB_PATH> with the actual path to your sqlite DB file. -v is used to enable verbose logging

Once the mailpit server starts, you can access it via 127.0.0.1:8025.

Other customization options can be found in their official documentation.

Bonus: Create alias to launch mailpit

alias mpit=mailpit -d "C:\\mailpit\\maildb.sqlite" -v $*

Wrapping Up

Thank you for reading! Hopefully, this guide on Mailpit configuration and use for offline email testing has been helpful. If you have any questions or need further assistance, please don't hesitate to contact us. We’d love to hear about your experiences with Mailpit or any other tools you use for email testing.

Stay connected for more tips and tutorials!

Happy coding!

Email us or Talk to us at +91-98367-81929 or Simply Contact Us through the website.