anvil.testing.email Module
This module contains helpers for testing server code that sends email.
Classes
SentEmail
Functions
capture_emails
Classes
SentEmail
An email the app’s code sent inside a capture_emails() block. Its attributes are the arguments the code passed to anvil.email.send().
SentEmail Attributes
attachments - list(anvil.Media instance)
The attachments.
bcc - bcc
The bcc argument the code passed to anvil.email.send(): a string, a list of strings, or None.
cc - cc
The cc argument the code passed to anvil.email.send(): a string, a list of strings, or None.
from_address - string
The from_address the code passed to anvil.email.send(), or None.
from_name - string
The from_name the code passed to anvil.email.send(), or None.
html - string
The HTML content, or None.
in_reply_to - string
The Message-ID this email replies to, eg when sent with Message.reply(), or None.
inline_attachments - dict(string,anvil.Media instance)
The inline attachments, by Content-ID.
message_id - string
The Message-ID that anvil.email.send() returned in its SendReport.
references - string
The References header, or None.
subject - string
The subject line, or None.
text - string
The plain-text content, or None.
to - to
The to argument the code passed to anvil.email.send(): a string, a list of strings, or None.
Functions
capture_emails()
Use in a with block to capture the emails the app’s code sends, including from background tasks and Message.reply().
Yields a list when the block ends, filled with SentEmail objects for the emails sent inside the block. Tests never send real email.
To check emails sent from background tasks, call anvil.testing.server.wait_for_background_tasks_to_finish() inside the block.
with capture_emails() as emails:
place_order(user, items)
[email] = emails
assert email.to == ["Alice <alice@example.com>"]
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.