Backend
A backend holds the configuration for sending through one mail service.
Usage
Backend(
*,
from_address,
)It holds immutable configuration and no live link, so threads can share it. It is not a context manager: connect() opens a link. A subclass implements _open() and nothing else. See ADR-0005 and ADR-0006.
Attributes
from_address: str- The mailbox every submission is sent from, checked at construction. No send can override it. See ADR-0001.
Attributes
| Name | Description |
|---|---|
| from_address | Return the from address, which has no setter because assigning one would skip the check (ADR-0005). |
from_address
Return the from address, which has no setter because assigning one would skip the check (ADR-0005).
from_address: str
Methods
| Name | Description |
|---|---|
| connect() | Open one live link and return the connection that holds it. |
| send() | Send one message over a connection opened and closed for it. |
connect()
Open one live link and return the connection that holds it.
Usage
connect()Opening is eager, so this call, not the first send, raises AuthenticationError and TransportError. A token endpoint that fails on the provider’s side raises ProviderError here too. See ADR-0005.
Use it in a with. A connection left unclosed holds its link until the service times it out.
Examples
from epistole import MemoryBackend, Message
backend = MemoryBackend()
with backend.connect() as connection:
connection.send(Message(text="Weekly numbers").to("ada@example.com"))
len(backend.submissions) # 1send()
Send one message over a connection opened and closed for it.
Usage
send(message)To send many messages, open one connection with connect() instead. When the service refuses some recipients and accepts the rest, the send raises nothing and SendResult.refused holds the refusals.