Extracting links from email and SMS

Learn how to test hyperlinks found in email and SMS messages 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.

When an email is sent with an HTML body, Mailosaur automatically extracts any hyperlinks found within anchor (<a>) and area (<area>) elements and makes these available via the html.links array.

Each link has a text property, representing the display text of the hyperlink within the body, and an href property containing the target URL.

Note that only links that have been correctly marked up in HTML will be detected.

// How many links?
console.log(message.html.links.length) // 2

const firstLink = message.html.links[0]
console.log(firstLink.text) // "Google Search"
console.log(firstLink.href) // ""

As with links found within the HTML content of an email, Mailosaur also detects and extracts links found within the plain text of a message (both email and SMS).

These are made available viable via the text.links array.

Each link has an href property containing the target URL. Whilst each link also has a text property, this will always have the same value as href.

// How many links?
console.log(message.text.links.length) // 2

const firstLink = message.text.links[0]
console.log(firstLink.href) // ""