Check out the latest Mailtrap Getting Started Guide covering the new features and providing step-by-step instruction on using Mailtrap basic functionality.
Mailtrap provides a fake SMTP server for your development team to test, view and share emails sent from the pre-production environments and test with real data without the risk of spamming real customers. It’s created by Railsware and for many development tasks, using Mailtrap will be free.
Essentially, you sign up for Mailtrap and send all of your pre-production environment email via your fake Mailtrap SMTP server.
Then, all of your mails belong to Mailtrap. You can view and debug your email within Mailtrap’s friendly GUI.
You can even use Mailtrap to place dumps of your production database with real user emails through tests on your staging server. Your automated tests can run against the real data—sending email via Mailtrap, eliminating the risk that test emails go out to real customer email addresses.
How Much Does Mailtrap Cost?
For small developers or small tasks, Mailtrap is free. For larger efforts, costs vary between $120 and $300 annually:
Getting Started With Mailtrap
Signing up is easy. You can even use your Google or GitHub account:
I used my GitHub account and the process was easy:
Once confirmed, you’ll see your demo inbox in the Mailtrap GUI:
Next, I’m going to walk you through setting up Mailtrap within your development environment.
When you click on the Demo inbox name in the inbox list, you’ll see SMTP server credentials which you should use in your application configuration:
Each Mailtrap inbox has its own SMTP server credentials. You can reset these credentials whenever you want.
Mailtrap also provides Email Address per each inbox where you can send your messages.
But this feature is available only for Bee-Trap Plan.
Mailtrap offers a variety of configuration examples:
For simplicity, I’ll use the Hello application from our Programming With Yii2 series to configure Mailtrap. If you wish to use the code from there to test Mailtrap, clone the GitHub repository linked to this tutorial.
With Yii, I’m updating the SwiftMailer SMTP settings in config/web.php. Here’s the default:
Yii sends a confirmation email:
Instantly, the message appears in my Mailtrap inbox.
Note: This is not to be confused with the Mailtrap account confirmation—it’s the Yii Hello app account confirmation email sent by my application.
The default display is what you might see in Gmail or another mail client:
But there are many tabs to choose from to debug your application’s outbound email. Here’s the HTML source:
Here’s a view of HTML validation against your email:
And here’s an analysis of the spam score and blacklisting of your message and server:
Mailtrap is such a powerful way to debug your outbound email message content and markup.
Sharing Inboxes and Messages With Your Team
If your team is larger, you can add your developers to each inbox and company.
You can invite users to a company with links:
Company users will be able to manage this company with all its inboxes. They can edit/delete inboxes, change inbox settings but they are not able to grant/withdraw admin rights to/from other users. Only owner (you) can do this. There can be only one owner per company.
In order to share messages of a particular inbox you can add users to that inbox at its settings page:
Inbox users can use that inbox, setup its forwarding rules but they are not able to edit, remove or share it.
The limit of company and inbox users are set according to your subscription plan. For instance, the account which has Fly-Trap plan is able to add 10 users for each company and 10 users for each inbox.
At the inbox settings page you can also set forwarding rules in order to automatically forward all messages to another users. There are 2 rules for automatic forwarding: Email and Domain:
- Email rule: you can specify an email address which will be set as TO or CC in your messages. When you send messages through Mailtrap the forwarding rule matches the values from the list and in your email message headers and if they match it forwards them.
- Domain rule: it matches domains inside TO or CC email headers with your domain values from the list.
The Mailtrap API
You can also write automated tests against Mailtrap mailbox content using its API, documented on apiary. In other words, you could run automated scripts against a snapshot of your live production database and verify the content and markup of the messages that would be delivered by your codebase using the Mailtrap API.
Want to Learn More?
Mailtrap’s capabilities and debugging features are obviously super useful and affordable. If you’d like to see another demonstration, here’s a lightning talk on Mailtrap by Yaroslav Lazor from Railsberry 2012:https://player.vimeo.com/video/44307833
It’s such a simple product to use and so beneficial that I hope you’ll give it a try on your own.