Skip to main content
EmailClient gives a test a real inbox. It creates an email address, waits for the email your application sends to it, and extracts its links and codes, so tests can cover OTPs, invite flows and notification emails. It can also send email from that address, so tests can cover apps that receive email. Every test repository managed by Empirical includes it, with no setup.

Usage

Dynamic email

Generates a random email address that can be used for the test (e.g. invite a new user).

Static email

Use a fixed address for an account that signs in to your application by email. Empirical appends @empiricalrun.email to the emailId you pass to get the full address. Claim the address (see below) so other projects can’t read its mail.

Filtering emails

You can filter emails by sender, subject, or body content. The subject and body filters use substring matching, so you don’t need to provide the full value. The from filter matches the sender in the From header, or the envelope sender that a mail provider such as Amazon SES uses for bounces.

Sending email

sendEmail sends an email from the client’s address, with optional attachments. Use it to test apps that process inbound email, such as reply-by-email, email-to-ticket or “forward your receipt” flows. Replies arrive at the client’s address, so waitForEmail reads them.
To reply in the same thread, pass the received email’s messageId as inReplyTo:

Who you can send to

Each recipient must be one of:
  • an @empiricalrun.email address
  • someone who emailed the sending address (replies always work)
  • an allowed recipient of your project: a verified domain, such as acme.com, or a verified address, such as support@acme.zendesk.com
A send to anyone else fails with a 403 error that names the recipients. To allow one, open Inboxes in the dashboard and press + next to Allowed recipients, or call Add an allowed recipient. Then verify it in one of two ways:
  • Email from it. Send an email from the domain (any mailbox on it) or from the exact address to the verification address shown, with the code in the subject. It verifies a few seconds after it arrives.
  • Emailed code, for an address that can’t send, such as a help desk or webhook address. Empirical emails it a 6-digit code; find the code where the address delivers (the ticket, the webhook payload) and enter it.
A domain covers exactly that domain, not its subdomains. Add a subdomain such as inbound.acme.com on its own; an email from @acme.com verifies it. Public mail providers such as gmail.com can’t be added as domains; add the exact address instead. An address also covers its +tag variants.

Limits

The sender must be unclaimed or claimed by your project, and the email has no display name. Sending has strict limits. An email over a size limit fails with a 400 error, and a send over a rate limit fails with a 429 error that names the limit:

Send options

sendEmail resolves to { messageId, sentAt }.

Email properties

The received email object has the following properties:

Client options

Wait options

Pass these values to waitForEmail to select the message you need:

Read an inbox outside a test

To set up an account that signs in by email, you need the mail it gets before any test runs, such as the first verification code. Claim an inbox for your project and read it in the dashboard or through the API.

In the dashboard

  1. Open Inboxes in your project and press + next to Inboxes. Enter a prefix, such as signup-user, and an optional label. Empirical appends a random suffix, so the address is your project’s only, for example signup-user-k3f9@empiricalrun.email.
  2. Sign up or sign in to the application with that address.
  3. Open the inbox. New mail shows up within a few seconds. Each message shows its codes as copy buttons and its links. Details shows the sender, the DMARC result and the Message-ID.
The Allowed recipients list on the same page is where you allow and verify the domains and addresses your tests send email to.

With the API

  1. Claim an address. Empirical appends a random suffix to prefix, so the address belongs to your project only.
    The response has the full address, for example signup-user-k3f9@empiricalrun.email, and the inbox id.
  2. Sign up or sign in to the application with that address.
  3. List the messages. Each one has the same links and codes as in a test.
An inbox shows only mail received after it was claimed. Mail is kept for 30 days. Addresses match regardless of case. A claimed address covers only that exact address, not +tag variants such as signup-user-k3f9+1@empiricalrun.email. Once an address is claimed, EmailClient in another project’s tests can’t read it. waitForEmail then fails with <address> is claimed by another project. To read any address from your own scripts, call List messages for an address with the address in to. The same claim rules apply. See Claim an inbox, List inbox messages and Send an email for every option.