Package turbomail :: Module dispatch :: Class Dispatch
[hide private]
[frames] | no frames]

Class Dispatch

source code

object --+
         |
        Dispatch

SMTP message dispatch class.

An instance of the Dispatch class is created for each SMTP connection. Usually, this means one Dispatch instance per running thread.

Example usage:

       import turbomail
       dispatch = turbomail.Dispatch("localhost")
       message = turbomail.Message(
                       "from@localhost",
                       "to@localhost",
                       "Subject",
                       plain="Hello world!"
               )
       dispatch(message)
Instance Methods [hide private]
 
__init__(self, server, username=None, password=None, tls=None, debug=False)
Initialize the Dispatch class.
source code
 
connect(self)
Connect to the SMTP server if not already connected.
source code
 
disconnect(self)
Disconnect from the SMTP server if connected.
source code
 
__call__(self, message)
Deliver a message via the current SMTP connection.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]
  connected
Return the current SMTP connection status.

Inherited from object: __class__

Method Details [hide private]

__init__(self, server, username=None, password=None, tls=None, debug=False)
(Constructor)

source code 

Initialize the Dispatch class.

Authentication is only performed if both username and password are not None. An instance of Dispatch is callable.

Parameters:
  • server (string) - The server (with optional port number) to connect this instance to.
  • username (string) - The username to use during authentication. Optional.
  • password (string) - The password to use during authentication. Optional.
  • debug (bool) - Enable SMTP verbose logging. This outputs all communications between the client and server.
Overrides: object.__init__

connect(self)

source code 

Connect to the SMTP server if not already connected.

This process also automatically enables TLS, if available, and authenticates against the username and password previously provided.

__call__(self, message)
(Call operator)

source code 

Deliver a message via the current SMTP connection.

Calling an instance of the Dispatch class will automatically connect, if needed, and will also automatically disconnect if debug mode has been enabled.

Parameters:
  • message (callable) - This parameter must be a callable which returns a tuple of (from, to, message), where all three are strings, and message is valid content for an e-mail message.

Property Details [hide private]

connected

Return the current SMTP connection status.

Get Method:
unreachable.connected(self) - Return the current SMTP connection status.