How to test email in local development with Mailpit

When developing projects that require sending emails, there are applications available that can be used to simulate the sending of emails to email accounts.

Mailpit is a great solution to supporting local development when working on email sending and templating.

mailpit-site.png

Install Mailpit

Here are a couple of methods to install Mailpit.

MacOS install via brew

With Brew installed use it to install mailpit.

brew install mailpit

Linux install

Run the following to install Mailpit in Linux.

This command was tested using the Ubuntu distribution.

sudo bash < <(curl -sL https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh)

Running Mailpit

After successful installation run the mailpit command to start up the application.

mailpit

Open the web browser and go to the URL http://localhost:8025 which will show the mailpit web UI.

mailpit-ui.png

Send a test email

Now to send a test email which will show up in mailpit.

Start by creating a new text file by using a text editor inside of the terminal.

nano email.txt

Copy and paste the following content, save the file and then exit the text editor. The email message text was generated using a Lorem ipsum generator.

From: [email protected]
To: [email protected]
Subject: This is a test email

Lorem ipsum dolor sit amet consectetur adipiscing elit quam a magna congue dapibus condimentum id, taciti mauris nisi luctus suscipit pretium sociosqu nam penatibus odio posuere himenaeos hendrerit. Ante ridiculus facilisi suscipit lobortis tortor eleifend ullamcorper aliquam per platea laoreet nibh sociis enim dui senectus, cras nam urna quis aenean dictum nisl habitasse massa metus lacus justo condimentum ac curabitur. Class ullamcorper sem vel risus gravida nisl luctus interdum vitae condimentum facilisis turpis ultricies, sociosqu penatibus enim primis sapien ultrices diam pharetra vulputate eleifend scelerisque tincidunt.

Now run the following command to send the email using the email.txt.

mailpit sendmail < email.txt

Go back to the mailpit website and you will see that the new email has appeared in the email list, also you will see a notification in the browser tab to get your attention if you are currently not on the mailpit tab.

mailpit-new-email.png

Click on the email list item and you will be able to see the full email on the view page.

mailpit-email-view.png