How to test Emails
Introduction
The majority of Web Applications send emails when certain actions are triggered.
In some cases, you may want access to those emails during your tests to confirm their delivery, check their contents, or extract information to use within your test.
For example, you can test registering a user account, receiving a verification email, clicking a link to verify the email address, and asserting that the email has been verified.
You can use our Endtest Mailbox to access emails.
The way it works is similar to a disposable email service.
It can be accessed manually or in an automated test, through the UI or with a script.
1. Access the Endtest Mailbox through the UI
Steps
- Choose an email address that has the
endtest-mail.io
domain. - Make sure your email gets sent to that email address.
- Add a
Pause
of 30 seconds or a Wait Until step. - Access the Endtest Mailbox for that email address with a
Go to URL
step.
Example:
Let's suppose you picked the following email address: bruce.wayne8@endtest-mail.io
You can access the Inbox for that email address by going to the following URL:
https://app.endtest.io/mailbox?email=bruce.wayne@endtest-mail.io
The email address doesn't need to be pre-registered on our side.
You can even generate a random string and prepend it to the @endtest-mail.io
string.
Or you can generate a random email address with the Random Email
option from Set Variable
action.
You can also open the Endtest Mailbox in a new browser tab, by using the Open new tab
option from the Miscellaneous
action.
In order to switch back to your initial browser tab, you can use the Switch to previous tab
option from the Miscellaneous
action.
If you're not sure how long it takes for your application to deliver the email, you can add a Wait Until
step that will also automatically refresh the page at certain intervals.
The Wait Until
option can be found in the Miscellaneous
action.
2. Access the Endtest Mailbox from a script
Steps
- Choose an email address that has the
endtest-mail.io
domain. - Make sure your email gets sent to that email address.
- Add a pause of 30 seconds in your script.
- Access the Endtest Mailbox in your script by sending a GET request to the
https://app.endtest.io/mailbox
endpoint with the following paramters:email
andformat
.
Currently, the only option is to fetch the emails in JSON format by using format=json
.
Let's suppose you picked the following email address: bruce.wayne8@endtest-mail.io
You can access the emails for that address with the following GET request:
https://app.endtest.io/mailbox?email=bruce.wayne@endtest-mail.io&format=json
The JSON response will have the following format:
[
{
fromName: '',
fromAddress: '',
toAddress: '',
subject: '',
html: '',
timestamp: ''
},
{
fromName: '',
fromAddress: '',
toAddress: '',
subject: '',
html: '',
timestamp: ''
}
]
The email address doesn't need to be pre-registered on our side.
You can even generate a random string and prepend it to the @endtest-mail.io
string.
3. Delete all the emails sent to an email address
Steps
Access the Endtest Mailbox in your test or script by sending a GET request to the https://app.endtest.io/mailbox
endpoint with the following parameters: email
and action=delete
.
Let's suppose you picked the following email address: bruce.wayne8@endtest-mail.io
You can delete the emails for that address with the following GET request:
https://app.endtest.io/mailbox?email=bruce.wayne@endtest-mail.io&action=delete
4. Using email subaddress
Steps
An email subaddress refers to the practice of adding a plus sign (+) and additional characters to the local part of an email address to create variations that still deliver to the same inbox.
For example, in the email batman+label@endtest-mail.io
, +label
is a form of subaddressing.
If you send separate emails to batman+1@endtest-mail.io
and batman+2@endtest-mail.io
, they will still be accessible in the Endtest Mailbox. Each email will be delivered to its own subaddressed variation without needing any special parameters.
However, if you include the subaddress=true
parameter, you can view all emails addressed to the base email, like batman@endtest-mail.io
, in one mailbox, regardless of the subaddress:
For Security reasons, it's mandatory to also add the from
parameter when using subaddress=true
.
The value provided in the from
parameter needs to match the email address from which those emails were sent.
And the subaddress=true
parameter can also be used to get the emails in JSON format or to delete the emails.
When accessing emails in the Endtest Mailbox, you should add a Wait Until step or a 30 second Pause step before the
Go to URL
step, to allow your web application to have enough time to send the email.Emails sent to this service are technically public and can be accessed by anyone with knowledge of the username being used.
While using a dynamic username provides some level of privacy, you should avoid inclusion of sensitive data in your emails when using this service.
Please note that the emails will be automatically deleted after 7 days.
Starting from June 4 2020,
Endtest Mailbox
will only work withendtest-mail.io
emails.You can also send emails with the Endtest Utilities.