## Backend


A backend holds the configuration for sending through one mail service.


Usage

``` python
Backend(
    *,
    from_address,
)
```


It holds immutable configuration and no live link, so threads can share it. It is not a context manager: [connect()](Backend.md#epistole.Backend.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](#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()](#connect) | Open one live link and return the connection that holds it. |
| [send()](#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

``` python
connect()
```


Opening is eager, so this call, not the first send, raises [AuthenticationError](exceptions.AuthenticationError.md#epistole.exceptions.AuthenticationError) and [TransportError](exceptions.TransportError.md#epistole.exceptions.TransportError). A token endpoint that fails on the provider's side raises [ProviderError](exceptions.ProviderError.md#epistole.exceptions.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

``` python
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)  # 1
```

------------------------------------------------------------------------


#### send()


Send one message over a connection opened and closed for it.


Usage

``` python
send(message)
```


To send many messages, open one connection with [connect()](Backend.md#epistole.Backend.connect) instead. When the service refuses some recipients and accepts the rest, the send raises nothing and `SendResult.refused` holds the refusals.
