Message properties

Learn how to test the common properties of an email or SMS message with Mailosaur.

Before you begin
A hashtag icon

The examples shown below are based on two key assumptions:

  1. That you have already create a basic automated test using our getting started guides.
  2. You have a chosen assertion library that you will use to test the values shown below.

Email subject
A hashtag icon

Allows you to check that the correct subject will be displayed in a recipient’s mail client.

console.log(message.subject) // "Hello world"

A hashtag icon

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([0].name) // "Jill Smith"
console.log([0].email) // ""

// Phone number (for SMS tests only)
console.log([0].phone) // "+15554532452"
console.log([0].name) // "Jack Smith"
console.log([0].email) // ""
console.log(message.bcc[0].name) // "Bob Smith"
console.log(message.bcc[0].email) // ""

A hashtag icon

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) // ""

// Phone number (for SMS tests only)
console.log(message.from[0].phone) // "+15554532452"

Email Headers
A hashtag icon

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); // "<>"