MailFlatDocs
Documentation/Common test cases/Links

Extracting and testing links in email

Every clickable link in a message is pulled out for you as an ordered, de-duplicated list, so magic-link and password-reset flows are one assertion away.

How it works

The links array holds every http and https URL in the message, in the order it appears, with duplicates removed. In HTML bodies we read marked-up links only (a and area tags) so tracking pixels and CSS URLs stay out of your way; in plain text bodies we pick up bare URLs, which is what most password-reset mails send. HTML entities are decoded, so a href with & comes back as a URL you can actually open.

Get the links

The SDKs do not type this field yet, so read it off raw — the untouched API payload every message carries.
msg = inbox.wait_for_message(timeout=30)
links = msg.raw["links"]
assert links[0].startswith("https://staging.example.com/verify")

Follow the magic link

The point of a magic link is that clicking it logs you in. Drive it with the same browser the test is already using.
# Playwright
page.goto(msg.raw["links"][0])
assert page.url.endswith("/dashboard")

Find one link among many

Marketing footers add links you do not care about. Match on the part of the URL that identifies the action.
verify = next(u for u in msg.raw["links"] if "/verify" in u)

Worth knowing

Only marked-up links, on purpose
In an HTML body we read a and area tags and nothing else. Scanning the raw HTML for anything URL-shaped drags in tracking pixels, CSS backgrounds and analytics beacons, which buries the one link your test is looking for.