Skip to main content

Receive Email

client.receiveEmail(address, callback = () => {});

This custom command will return an array of email messages that were sent to the specified email address during test execution. To generate the email address, you should use the genEmail function.

The command itself will not wait for any messages to arrive, so it's recommended to use it within a loop that will wait for the email to be visible within the the array.

The emails will be available within the provided callback function as an array. The email message object will have the following properties:

  • from - The email address of the sender.
  • subject - The subject of the email.
  • headers - The headers of the email.
  • text/plain - The plain text content of the email.
  • text/html - The HTML content of the email.

The email message object is a JavaScript object, so it is possible to access the properties using the dot notation, for example: email.from, but since the property names contain special characters, it is not recommended. Instead, it is recommended to access the properties using the array notation, for example: email["from"], by doing this you will avoid any potential issues with the special characters.

client => {
client.genEmail("test", addr => {
client.receiveEmail(addr, emails => {
console.log(`Amount of received emails: ${emails.length}`)

for (let email of emails) {
console.log(`From: ${email["from"]}`)
console.log(`Subject: ${email["subject"]}`)
console.log(`Plain text content: ${email["text/plain"]}`)