MailFlatDocs
Documentation/Common test cases/Plain text content

Asserting on plain text email content

The text part of a message, exactly as sent. Simpler to assert on than HTML, and the part most transactional senders get wrong.

How it works

body_text is the plain text alternative of the message. Deliverability tools penalise senders who ship HTML with no text part, so asserting that this field exists and reads properly is a real test, not a formality.

Assert on the copy

Whitespace in email bodies is unreliable — normalise before comparing exact strings.
msg = inbox.latest()
assert "reset your password" in msg.text.lower()
assert msg.text.strip(), "the message shipped without a text part"

Both parts, one message

A well-formed transactional email carries text and HTML. Assert on both when the template is what you are testing.
assert msg.text, "missing plain text part"
assert msg.html, "missing HTML part"