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.
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
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 console.log(firstLink.text) // "Google Search" console.log(firstLink.href) // "https://www.google.com/"
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
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
// How many links? console.log(message.text.links.length) // 2 const firstLink = message.text.links console.log(firstLink.href) // "https://www.google.com/"