MemoryBackend

A memory backend records each submission instead of sending it.

Usage

Source

MemoryBackend(
    *,
    from_address="epistole@example.invalid",
    refuse=None,
)

See ADR-0015 for its design.

Parameters

refuse: Mapping[str, Refusal] | None = None
Maps an address to the refusal it gets, matched by addr-spec. A key that is not an address raises here, rather than never matching.

Attributes

submissions: list[Submission]
Every submission at least one recipient accepted, from every connection, in the order the submits completed. Reset it with list.clear().

Examples

from epistole import MemoryBackend, Message, Refusal

backend = MemoryBackend(from_address="reports@example.com")
backend.send(Message(text="Weekly numbers").to("ada@example.com"))

backend.submissions[0].message.to_  # ("ada@example.com",)
backend.submissions[0].from_address  # "reports@example.com"

Refuse one recipient, and the backend accepts the rest, as SMTP does:

backend = MemoryBackend(refuse={"ada@example.com": Refusal(550, "No such mailbox")})
result = backend.send(
    Message(text="Weekly numbers").to("ada@example.com", "bob@example.com")
)

result.refused  # {"ada@example.com": Refusal(code=550, reason="No such mailbox")}

Attributes

Name Description
submissions Return the list every connection appends to, which has no setter because an open connection would keep appending to the old one (ADR-0005).

submissions

Return the list every connection appends to, which has no setter because an open connection would keep appending to the old one (ADR-0005).

submissions: list[Submission]