Before you begin
The examples shown below are based on two key assumptions:
- That you have already create a basic automated test using our getting started guides.
- You have a chosen assertion library that you will use to test the values shown below.
Email subject
Allows you to check that the correct subject will be displayed in a recipient’s mail client.
console.log(message.subject) // "Hello world"
Recipients
The to
property of a message contains an array of all recipients of a message (excluding those that have been carbon-copied on an email).
console.log(message.to[0].name) // "Jill Smith"
console.log(message.to[0].email) // "jill@example.com"
// Phone number (for SMS tests only)
console.log(message.to[0].phone) // "+15554532452"
Carbon copy (CC) recipients
console.log(message.cc[0].name) // "Jack Smith"
console.log(message.cc[0].email) // "jack@example.com"
Blind carbon-copy (BCC) recipients
console.log(message.bcc[0].name) // "Bob Smith"
console.log(message.bcc[0].email) // "bob@example.com"
Sender
The from
property of a message contains an array of senders. In almost all cases there will only be 1, however the email specification technically allows for multiple senders to exist.
console.log(message.from[0].name) // "Customer Support"
console.log(message.from[0].email) // "noreply@example.com"
// Phone number (for SMS tests only)
console.log(message.from[0].phone) // "+15554532452"
Email Headers
Emails contain a set of headers that are used to transmit metadata which is typically not visible to the recipient.
All email headers are available via the metadata.headers
property of a message. Each header has both a field
and value
property.
const headers = message.metadata.headers
const returnPath = headers.find(
h => h.field.toLowerCase() === 'return-path'
)
console.log(returnPath.value); // "<rp@example.com>"
Previous
Images and web beacons