# ``twisted`.`mail`.`relaymanager`.`SmartHostSMTPRelayingManager``

class documentation

`class SmartHostSMTPRelayingManager: (source)`

Known subclasses: `twisted.mail.relaymanager.SmartHostESMTPRelayingManager`

View In Hierarchy

A smart host which uses SMTP managed relayers to send messages from the relay queue.

`checkState` must be called periodically at which time the state of the relay queue is checked and new relayers are created as needed.

In order to relay a set of messages to a mail exchange server, a smart host creates an attempt manager and a managed relayer factory for that set of messages. When a connection is made with the mail exchange server, the managed relayer factory creates a managed relayer to send the messages. The managed relayer reports on its progress to the attempt manager which, in turn, updates the smart host's relay queue and information about its managed relayers.

Method | `__getstate__` | Create a representation of the non-volatile state of this object.
Method | `__init__` | Initialize a smart host.
Method | `__setstate__` | Restore the non-volatile state of this object and recreate the volatile state.
Method | `checkState` | Check the state of the relay queue and, if possible, launch relayers to handle waiting messages.
Constant | `PORT` | The port over which to connect to the SMTP server.
Instance Variable | `factory` | A callable which creates a factory for creating a managed relayer. See `SMTPManagedRelayerFactory.__init__` for parameters to the callable.
Instance Variable | `fArgs` | Positional arguments for `SMTPManagedRelayerFactory.__init__`.
Instance Variable | `fKwArgs` | Keyword arguments for `SMTPManagedRelayerFactory.__init__`.
Instance Variable | `managed` | A mapping of factory for a managed relayer to filenames of messages the managed relayer is responsible for.
Instance Variable | `maxConnections` | See `__init__`.
Instance Variable | `maxMessagesPerConnection` | See `__init__`.
Instance Variable | `mxcalc` | A resource for mail exchange host lookups.
Instance Variable | `queue` | See `__init__`.
Method | `_cbExchange` | Initiate a connection with a mail exchange server.
Method | `_checkStateMX` | Undocumented
Method | `_ebExchange` | Prepare to resend messages later.

def __getstate__(self): (source)
Create a representation of the non-volatile state of this object.

Returns
`dict` mapping `bytes` to `object` | The non-volatile state of the queue.

def __init__(self, queue, maxConnections=2, maxMessagesPerConnection=10): (source)

Initialize a smart host.

The default values specify connection limits appropriate for a low-volume smart host.

Parameters
queue:`Queue` | A relay queue.
maxConnections:`int` | The maximum number of concurrent connections to SMTP servers.
maxMessagesPerConnection:`int` | The maximum number of messages for which a relayer will be given responsibility.

def __setstate__(self, state): (source)
Restore the non-volatile state of this object and recreate the volatile state.

Parameters
state:`dict` mapping `bytes` to `object` | The non-volatile state of the queue.

def checkState(self): (source)
Check the state of the relay queue and, if possible, launch relayers to handle waiting messages.

Returns
`None` or `Deferred` | No return value if no further messages can be relayed or a deferred which fires when all of the SMTP connections initiated by this call have disconnected.

PORT: `int` = (source)
The port over which to connect to the SMTP server.

Value

    25

factory: callable which returns `SMTPManagedRelayerFactory` = (source)
overridden in `twisted.mail.relaymanager.SmartHostESMTPRelayingManager`
A callable which creates a factory for creating a managed relayer. See `SMTPManagedRelayerFactory.__init__` for parameters to the callable.
fArgs: 3-`tuple` of (0) `list` of `bytes`, (1) `_AttemptManager`, (2) `bytes` or 4-`tuple` of (0) `list` of `bytes`, (1) `_AttemptManager`, (2) `bytes`, (3) `int` = (source)
Positional arguments for `SMTPManagedRelayerFactory.__init__`.
fKwArgs: `dict` = (source)
Keyword arguments for `SMTPManagedRelayerFactory.__init__`.
managed: `dict` mapping `SMTPManagedRelayerFactory` to `list` of `bytes` = (source)
A mapping of factory for a managed relayer to filenames of messages the managed relayer is responsible for.
maxConnections = (source)
See `__init__`.
maxMessagesPerConnection = (source)
See `__init__`.
mxcalc: `None` or `MXCalculator` = (source)
A resource for mail exchange host lookups.
queue = (source)
See `__init__`.
def _cbExchange(self, address, port, factory): (source)

Initiate a connection with a mail exchange server.

This callback function runs after mail exchange server for the domain has been looked up.

Parameters
address:`bytes` | The hostname of a mail exchange server.
port:`int` | A port number.
factory:`SMTPManagedRelayerFactory` | A factory which can create a relayer for the mail exchange server.

def _checkStateMX(self): (source)

Undocumented

def _ebExchange(self, failure, factory, domain): (source)

Prepare to resend messages later.

This errback function runs when no mail exchange server for the domain can be found.

Parameters
failure:`Failure` | The reason the mail exchange lookup failed.
factory:`SMTPManagedRelayerFactory` | A factory which can create a relayer for the mail exchange server.
domain:`bytes` | A domain.