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.
html.images property of a message contains an array of images. The length of this array corresponds to the number of images found within an email.
console.log(message.html.images.length) // 2
Each attachment contains both a
src attribute, which contains the location of the image, as well as an
alt attribute holding the alternative, text description of the image.
Emails will often contain many images that are hosted elsewhere, such as on your website or product. It is recommended to check that these images are accessible by your recipients.
All images should have an alternative text description, which can be checked using the
const image = message.html.images console.log(image.alt) // "Hot air balloon"
In addition, to check that the image itself is accessible, you can use the
src attribute to perform an HTTP request to that address.
const https = require('https') // ... const image = message.html.images console.log(image.src) // "https://example.com/s.png?abc123" // Make an HTTP call to trigger the web beacon https.get(image.src, r => console.log(r.statusCode)) // 200
A web beacon is a small image that can be used to track whether an email has been opened by a recipient.
Because a web beacon is simply another form of remotely-hosted image, you can use the same code shown above to trigger an open email event.
When an image is embedded within the content of an email, its
src attribute will contain a “content ID” (e.g.
Where a content ID is present, the image itself will be attached to the email, and so can be access in the same way as any other attachment. Note that the
contentId attribute of the attachment will match the value found in the
src attribute, excluding the
const embeddedImage = message.html.images console.log(embeddedImage.src) // "cid:ii_1435fadb31d523f6" console.log(embeddedImage.alt) // "Hot air balloon"