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. Thesubject 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.
messageId as
inReplyTo:
Who you can send to
Each recipient must be one of:- an
@empiricalrun.emailaddress - 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 assupport@acme.zendesk.com
+ 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.
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 towaitForEmail 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
- Open Inboxes in your project and press
+next to Inboxes. Enter a prefix, such assignup-user, and an optional label. Empirical appends a random suffix, so the address is your project’s only, for examplesignup-user-k3f9@empiricalrun.email. - Sign up or sign in to the application with that address.
- 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.
With the API
-
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 examplesignup-user-k3f9@empiricalrun.email, and the inboxid. - Sign up or sign in to the application with that address.
-
List the messages. Each one has the same
linksandcodesas in a test.
+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.