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.
Links within email and SMS text content
When an email or SMS message is sent with plain text content, Mailosaur automatically extracts anything that look like a verification code and makes these available via the text.codes
array. Each code has a value
property, representing the code itself.
// How many codes?
console.log(message.text.codes.length) // 2
const firstCode = message.text.codes[0]
console.log(firstCode.value) // "456812"
Links within email HTML content
As with links found within the text content of a message, Mailosaur also detects and extracts codes found within the HTML of any email.
These are made available viable via the html.codes
array.
// How many codes?
console.log(message.html.codes.length) // 2
const firstCode = message.html.codes[0]
console.log(firstCode.value) // "456812"
What if my code is not detected?
Mailosaur automatically detects most common verification code patterns, however you can still write your own regular expressions to meet more specific requirements.
See also
Previous
Extracting links from email and SMSNext
Email attachments