client Module

This module contains the SMTP client class Session for relaying mail to other SMTP servers.

pymail.client.CONNECT_TIMEOUT = 10

Time out in seconds for socket connect

exception pymail.client.ClientException

Bases: exceptions.RuntimeError

Exception raised when response from SMTP server is not the expected one

class pymail.client.Session(mailHosts, clientAddress, messageId, source, destination, credentials=(None, None))

Bases: object

SMTP session

Synopsis:

session = client.Session(hostsToTry, myClientDomain, messageId, sourceMailAddr, destinationMailAddr, (user, passw))
session.start()
session.startData()
session.sendData(msg)
session.endData()
session.close()
__init__(mailHosts, clientAddress, messageId, source, destination, credentials=(None, None))

Create Client object

Parameters:
  • mailHosts (string-list) – a list of domain names (possibly from a MX query) to try
  • clientAddress (string) – own domain name for EHLO
  • messageId (string) – message ID (only used for logging)
  • source (string) – source e-mail address
  • destination (string) – destination e-mail address
  • credentials (tuple) – optional tuple with username and password for authentication with server
clientAddress = None

Client address to use in protocol

close()

Close connection

Raises ClientException:
 on improper response from QUIT command

Signs off with the SMTP server

credentials = None

Credentials (username, password)

dataSize = None

DATA bytes sent

destination = None

Destination e-mail address

endData()

Send terminating dot line and switch to COMMAND_MODE

host = None

Connection host (effective)

log = None

Logger

mailHosts = None

Address of server to contact

messageId = None

Message ID

plain(port)

Open connection to port 25, negotiate an SMTP session without authentication

Parameters:

port (int) –

Raises:
  • ClientException
  • TemporaryError

Opens a connection, sends EHLO and receives server response. No AUTH authentication is attempted since the connection is not encrypted. If the server insists on an authentication, this connection will fail.

port = None

Connection port

read()

Read server response

Returns:list of tuples (code, text)
Raises ClientException:
 on unparsable response from server

Reads a server response, possibly with dash continuations and returns all in a list

sendData(data)

Send body

Parameters:data (string) –

Send data as-is. startData() must have been called before.

sendLine(msg)

Send line

Parameters:msg (string) –

Sends a line and terminates it by CR/LF.

serverResponseRe = <_sre.SRE_Pattern object at 0x1f79430>

Regex to parse an SMTP server response

socket = None

Socket (set in one of the open...() methods)

sockfile = None

Socket file (set in one of the open...() methods)

source = None

Source e-mail address

start()

Start client session

startData()

Send a DATA command and switch to DATA_MODE

Raises ClientException:
 
starttls(port)

Open connection and negotiate an SMTP session until after optional PLAIN authentication

Parameters:

port (int) –

Raises:
  • ClientException
  • TemporaryError

Opens a connection, sends EHLO and receives server response, which must include a STARTTLS message. If the server supports PLAIN authentication and username and password are provided in configuration, an authentication is done.

status = None

Protocol status

tls(port)

Open connection and negotiate an SMTP session until after optional PLAIN authentication

Parameters:

port (int) –

Raises:
  • ClientException
  • TemporaryError

Opens a connection in SSL, sends EHLO and receives server response. If the server supports PLAIN authentication and username and password are provided in configuration, an authentication is done.

exception pymail.client.TemporaryError

Bases: exceptions.RuntimeError

Exception raised when a temporary error prevented a connection

pymail.client.collected(items)

Format a list into lines

Parameters:items (list) –
Returns:string with items on a line be themselves