4 reasons to use an email testing service

In this article, we list four key reasons as to why you should be using an email testing service.

Around 200 billion emails are being sent each day. Many of these are transactional in nature, including account signup and order confirmation emails. Have you ever received one such email that had a broken link, preventing you from completing a transaction with the sender?

Email testing, whether manual or automated, could have prevented this issue. With manual email testing, a developer would have first created the email and sent it to a designated address in an email client, before viewing it, checking links, and fixing any issues found. The developer would repeat this process many times over with other email clients.

Yet manual testing is not immune to human error, not to mention the burden of laboriously testing a single email.

Enter automated email testing services.

What is an email testing service?

Before we explore why you should be using an email testing service, let’s first clarify what we mean by the term.

An email testing service typically hosts your email infrastructure and provides tools to enable easy testing, including spam analysis, validation of the HTML email body, and testing of email headers. It can be easily integrated with your project language and framework, making it simple to incorporate into existing projects.

A testing service can simulate real-world scenarios, such as a recipient responding to a “no-reply” email or clicking on a link in the email body, without ever reaching a real recipient or even a real email provider.

Generally speaking, an email testing service attempts to combine all necessary functionality in a single platform, thus eliminating the need for separate tools.

Our 4 top reasons to use an email testing service

While there are many free email testing tools to help along the testing process, using such tools in isolation can come with drawbacks that you would avoid with an email testing service. An automated email testing service allows for thorough functionality testing without the added burden of setting up and maintaining your own email infrastructure.

Below we’ll list four key reasons as to why you should be using an email testing service.

  1. Efficiently test email deliverability

With an email testing service, you can test whether an email can be successfully sent and received. By ensuring that emails get sent as expected, you can prevent a situation when code misbehaves in production. For example, your application can successfully deliver an email as expected in development and testing, yet fail in a production environment.

By using a virtual SMTP server, developers can avoid sending emails to real addresses or clients and still monitor the entire process as it would behave in a real situation.

  1. Easily preview emails across clients

Developers must also be mindful of how their emails appear to their audience. Testing an email’s appearance with just one email client does not suffice, seeing as no two email clients are the same. For example, an email that might look as expected in Outlook may not show up the same in Gmail or Yahoo mail. Appearance can also differ across device types and between the plain text and HTML versions of an email.

A testing service can help tackle these issues, including by displaying screenshots of how a given email would appear across different email clients and device types. Manually gathering such data would otherwise be very time consuming.

  1. Automate testing of your email content

The core of an email is the content being sent to the recipient. Does your email have a client-friendly subject line? Are there any spelling errors in the body text? Does your email include contact details in the sign-off?

Depending on your needs, automated email content tests can ensure that you haven’t missed anything content-wise. You can also include tests to check for information that shouldn’t be included, e.g., to avoid the inadvertent disclosure of confidential information. An email testing service helps you create these tests while using the tools you’re already familiar with like unit test frameworks.

  1. Quickly check links

Another email test that a service can assist with is to check for dead or erroneously-typed links. This is especially important in the case of transactional emails. For example, you might have a customer that needs to reset their password. If the link provided is invalid or if it does not direct the customer to the correct page, your customer might not access their account, potentially resulting in a lost sale or business opportunity.

As another example, your customer could be trying to confirm their subscription, yet an incorrect link might be preventing them from taking that action. This could lead to multiple issues, such as decreasing the customer’s trust in the service and possibly leading them to consider another service instead.

When using an email testing service, you can write tests that check the links for all types of emails your application might send—and you won’t need to worry about validating the links manually.

How to get started with an email testing service

Having covered why you should be using an email testing service, let’s now look at how you can actually get started. We’ll take Mailosaur as our example (it’s the one we know best!).

The first step is to sign up for the service itself. By signing up you can get an email address that you can send test emails to.

Following sign-up, it’s time to choose the right library for your programming language and framework. A service’s library should allow you to plug the service into your testing code. If you’re using [Cypress]({{<ref "blog/what-is-cypress" >}}), for example, use your service’s documentation for instructions on how to use the service within your code. In Mailosaur’s case, you would find all necessary instructions here.

Then comes the exciting part: writing your first email test. Let’s return to our example of the password reset email and now create a test in Javascript using Cypress. The goal is to request a new password link to be sent by email and then have the test find the message in our email server.

You can start by creating a spec file by the name of password-reset.cy.js in the Cypress directory:

touch cypress/e2e/password-reset.cy.js

After that, it’s time to edit the file contents. For starters we need to declare the server ID and which email the password reset should be sent to:

describe('Password reset', () => {
  const serverId = 'SERVER_ID';
  const testEmail = 'something@${serverId}.mailosaur.net'

If using Mailosaur, you would need to replace SERVER_ID and {serverId} with the actual server ID that was provided at sign-up.

Next, add the remaining code to request a password reset link and then retrieve the email using the following code:

it('Makes a Password Reset request', () => {
  cy.visit('https://example.org/password_reset')
  cy.title().should('equal', 'Forgot your password?')
  cy.get('#email_field').type(testEmail)
})

it('Gets a Password Reset email', () => {
  cy.mailosaurGetMessage(serverId, {
    sentTo: testEmail
  }).then(email => {
    expect(email.subject).to.equal('Reset your password');
    passwordResetLink = email.text.links[0].href;
  })
})

it('Follows the link from the email', () => {
  const validPassword = 'delighted cheese jolly cloud'
  cy.visit(passwordResetLink)
  cy.title().should('contain', 'Change your password')
  cy.get('#password').type(validPassword)
  cy.get('#password_confirmation').type(validPassword)
  cy.get('form').submit()
})

For more details on how to use mailosaurGetMessage and other functions from the Mailosaur library, check out the library reference docs.

Once you’ve finally created the tests you’ll be needing, all that’s left is to use the remaining email testing service functionality to run those tests, catch errors, and create impeccable emails that are ready to be sent to real-life users.

Mailosaur: email testing for developers, by developers

By now you’re well aware that getting started with Mailosaur is quick and easy. Mailosaur is an end-to-end email testing service that allows for test automation, message viewing, spam analysis, and so much more.

Check out our documentation to get started today!