Introduction
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 for supporting local development when working on email sending and templating.
Install Mailpit
Here are a couple of methods to install Mailpit, both methods should be usable in both MacOS and Linux.
If you are using the Windows operating system then the install file is available at the GitHub releases page, simply download the zip file, unzip, and double-click the exe file to install.
Brew install
With Brew installed use it to install the Mailpit tool.
brew install mailpit
Bash install
Run the following to install Mailpit using the bash script.
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, you can now run Mailpit.
If you installed via Brew then use it to run as a service.
brew services start mailpit
And for bash install use the following command.
mailpit
Open the web browser and go to the URL http://localhost:8025 which will show the mailpit web UI.
Send a test email
Now send a test email which will show up in the mailpit.
Start by creating a new text file using a text editor inside 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.
Click on the email list item and you will be able to see the full email on the view page.