EmailSecuritySoftwareUsability

Gaining Insight into Mailtrap: Test Your Emails Safely

3 Mins read

Mailtrap is a fake SMTP server created by Railsware. Using this service you can view, test, and share emails sent from the staging environment. The server lets you carry out an extensive testing using real data without spamming your real customers.

To start using the services of Mailtrap, you need to register on its server and set up your development and staging environment in such a way that the emails you send will go via SMTP to the Mailtrap server.

From that moment on, your emails will be caught by Mailtrap.

While developing and testing you can use the real email addresses of your customers. Mailtrap prevents test emails from being sent to real clients, therefore, you can be sure you won’t spam them accidentally.

Mailtrap Pricing

Mailtrap is free for small teams of developers or small projects. For larger projects, the price varies from $120 to $300 per year:

How to Start Using Mailtrap

To become a happy user of Mailtrap, you just need to sign up. You can join using your Google or GitHub account:

If you use your GitHub account, the signing in will go like this:

Once you authorized, your demo inbox will appear in the Mailtrap interface:

Coordinating Mailtrap and Your Development Environment

Your next step should be to set up Mailtrap server to your development environment.

Find the Settings icon in the inbox list and click on it. Each of the Mailtrap inboxes has its own SMTP server credentials:

There is an option to reset the credentials and you can do it at any time.

A lot of different configuration examples are offered by Mailtrap:

For example, let’s take the Hello application from the Yii2 series and configure Mailtrap. If you would like to use the same code to test Mailtrap, you can clone the GitHub repository. You can find the link below.

Using Yii, update the SwiftMailer SMTP settings in config/web.php. The default looks like this:

‘errorHandler’ => [
  ‘errorAction’ => ‘site/error’,
],
‘mailer’ => [
  ‘class’ => ‘yiiswiftmailerMailer’,
  ‘viewPath’ => ‘@app/mailer’,
  ‘useFileTransport’ => false,
  ‘transport’ => [
    ‘class’ => ‘Swift_SmtpTransport’,
    ‘host’ => ‘your-smtp-host-domain’,
    ‘username’ => ‘your-email-or-username’,
    ‘password’ => ‘your-password’,
    ‘port’ => ‘587’,
    ‘encryption’ => ‘tls’,
  ],
],
‘log’ => [
  ‘traceLevel’ => YII_DEBUG ? 3 : 0,

Then, change it with your Mailtrap settings:

‘errorHandler’ => [
  ‘errorAction’ => ‘site/error’,
],
‘mailer’ => [
  ‘class’ => ‘yiiswiftmailerMailer’,
  ‘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 that, go http://localhost:8888/hello/user/register to sign up again:

Yii will send you a confirmation email:

The messages will immediately appear in your Mailtrap inbox.

You should not confuse this message with the Mailtrap account confirmation. The message you can see in the picture above is the Yii Hello app account confirmation email sent by the exemplified app.

Here what the confirmation email looks like:

You can choose from a range of tabs to debug your application’s outbound email.

The HTML source is as follows:

The pic of HTML validation email:

The analysis of the spam score and blacklisting both of your message and server:

Now, you have a clear idea of how Mailtrap works.

How to Share Inboxes and Messages with the Team Members

To let your co-workers have an access to the mailboxes, invite them by sending them a link:

Also, you can specify which emails will be forwarded automatically:

The Mailtrap API

Using the API, you can write the automated tests that will check the content of the emails. Read the Mailtrap API documentation at http://docs.mailtrap.apiary.io/# .You can automatically run the scripts and work with real data of your app in order to verify the content and the makeup of the emails containing real data.

Leave a Reply

Your email address will not be published. Required fields are marked *