Checking Email within Tests

It’s common for websites and applications to send emails when certain actions are triggered. In some cases, you may want access to those emails during your test(s) to confirm their delivery, check their contents, or extract data for use within your test. While Ghost Inspector can often access 3rd party webmail clients, it's often challenging and not recommended. Instead, Ghost Inspector includes a built-in email service that can be used to seemlessly access triggered emails during your browser tests.

Table of Contents

  • Video Tutorial
  • How to use the Ghost Inspector Email Service
  • Dynamic Email Addresses
  • Checking Email while Maintaining Sessions

Video Tutorial

How to use the Ghost Inspector Email Service

To use our built-in email service, simply send your email(s) to a <username> email address (where <username> can be anything you choose). For instance, you can choose something like However, it is much more likely that you'll want use a unique or time-based username that is generated for each specific test run.

Once delivered, your email will be immediately accessible at a URL via our email service for 1 hour. The email's page will include sender details, subject, date and body. Email attachments will be shown in a list which includes their file name, type and size; however their contents will not be included so they cannot be accessed directly.

  • Emails sent to this service are technically public and can be accessed by anyone with knowledge of the <username> being used. While using a unique <username> with a dynamic portion (which we suggest below) provides some level of privacy, we insist that you avoid inclusion of sensitive data in your emails when using this service.
  • Emails are purged 1 hour after they are received.
  • This service is specifically designed to receive emails which you plan to access and use during a test. It is not designed to receive mass mailing, which may impact performace. Please refrain from sending large volumes of email to this service.

When an email is sent to a <username> email address, two different URLs can be used for accessing it.<username>
This URL will provide a simple “Inbox” view of all emails send to this address within the last hour.

Email service inbox<username>/latest
This URL will display the latest email sent to this address within the last hour (provided that one exists).

Sample email message

To use this service in your tests, simply assign a <username> email address, add a 30 second “Pause” step after the email is triggered to allow for delivery, then navigate to the email service's public URL within your test and interact with the email.

Email steps - Static email address

Dynamic Email Addresses

In many cases, it's going to be useful (or necessary) to use a unique email address — for instance, when testing your application's sign up process. We suggest using our built-in `{{TIMESTAMP}}` variable for this. You can create an {{emailUser}} variable containing a time-based username, then use that variable in the email address that you send to and check in your test.

Email steps - Dynamic email address

Checking Email while Maintaining Sessions

In some cases, you may need to extract a value from an email while keeping you browser test on an open page. For instance, you may submit a form in your application which prompts you for a code that is emailed. You'll need the browser to keep your application open while the email is accessed and code is fetched. In this case, we recommend opening up our email service in a popup window. This can be done with a simple JavaScript snippet, rather than a "Go to URL" step (which will navigate away from your application):'{{emailUser}}/latest')

Simply place that snippet into an Execute JavaScript step to open the email service in a popup window. We have some details on interacting with popup windows, but in general, the system will figure out which window the target element exists in (as long as the selector is unique across all windows). Below is an example that triggers an email, extracts a value from the email in a popup window, then assigns that value back into the main window.

Email steps - Dynamic email address in a popup window