Mailtrap is a fake SMTP server designed by Railsware for development teams. This tool enables you to view, share, and test emails received from the development or the staging environment. Using this server, you can work with real data without spamming your real clients. You can also check emails for blacklists, test the support of HTML, and advance your API testing.

Mailtrap somewhat captures emails you send to the real addresses of your audience. As a result, you can freely to test and develop any technologies and not sending spam by mistake. Now, let’s figure out how to actually use this service. As the first, you should register on the Mailtrap server and configure your staging and development environment to it so you will be able to direct your emails through SMTP to Mailtrap.

Mailtrap: The Tool for Testing Your Emails

How much does it cost?

Fees you pay for using Mailtrap depend on your project scale. If you work in a team developing a small project, it is free. However, if you work on a big project, it will cost you from $120 to $300 in a year.

Getting started

Your initial step should be signing up to the Mailtrap server. This can be done via your Google or GitHub account. If you choose the second way, Mailtrap will ask permission to connect your account – you will need to authorize your application. After everything is done, your demo inbox will show up in the Mailtrap interface. You can read about testing SMTP via command line.

How to configure Mailtrap to the development environment

What you need to do next is set up the server to your development environment. First, click on the Settings icon in your inbox list. Every Mailtrap inbox features its own SMTP server credentials that you can reset whenever it is necessary. You can configure Mailtrap in diverse ways; let’s now have a look at how to do it via the Hello application from the Yii2 series.
To use the same code for testing Mailtrap, make a copy of the GitHub repository. With the help of Yii, update the settings of SwiftMailer SMTP in config/web.php. This is how the default settings look like:

‘errorHandler’ => [

‘errorAction’ => ‘site/error’,

],

‘mailer’ => [

‘class’ => ‘yii\swiftmailer\Mailer’,

‘viewPath’ => ‘@app/mailer’,

‘useFileTransport’ => false,

‘transport’ => [

‘class’ => ‘Swift_SmtpTransport’,

‘host’ => ‘your-smtp-host-domain’,

‘username’ => ‘your-emil-or-username’,

‘password’ => ‘your-password’,

‘port’ => ‘587’,

‘encryption’ => ‘tls’,

],

],

‘log’ => [

‘traceLevel’ => YII_DEBUG ? 3 : 0,

 

Now, use the Mailtrap settings in order to change it:

 

‘errorHandler’ => [

‘errorAction’ => ‘site/error’,

],

‘mailer’ => [

‘class’ => ‘yii\swiftmailer\Mailer’,

‘viewPath’ => ‘@app/mailer’,

‘useFileTransport’ => false,

‘transport’ => [

‘class’ => ‘Swift_SmtpTransport’,

‘host’ => ‘mailtrap.io’,

‘username’ => ‘294XXXXXXXXXXdd20’,

‘password’ => ‘403XXXXXXXXXX2f7’,

‘port’ => ’25’,

‘encryption’ => ‘tls’,

],

],

‘log’ => [

‘traceLevel’ => YII_DEBUG ? 3 : 0,

After it is done, you need to sign up again. Go to http://localhost:8888/hello/user/register.
You will receive a confirmation email from Yii. Complete the registration by clicking the confirmation link in this email. Once you do it, the messages instantly appear in your Mailtrap inbox.

Keep in mind that this message is not the same as the Mailtrap account confirmation. The email to confirm your account will be sent to you after you sign up.

To debug the outbound email of your application, choose one of the tabs specified in the confirmation field.
Sharing inboxes and messages with your team

Once you register and update all the settings, you should give your colleagues access to the mailboxes. To that end, send them an invitation link found in the “My Inboxes company” section.
Likewise, you can put in the emails that you wish to forward automatically.

Mailtrap API

This feature enables you to create the automated tests for checking the email content. To work with it, study the Mailtrap API documentation at this link.