Implements an Edge that receives messages with the SMTP protocol. Attempts to follow the SMTP server RFCs.

class slimta.edge.smtp.SmtpEdge(listener, queue[, pool=None[, max_size=None[, validator_class=None[, auth=False[, context=None[, tls_immediately=False[, command_timeout=None[, data_timeout=None[, hostname=None[, session_class=None]]]]]]]]]])

Bases: slimta.edge.EdgeServer

Class that uses slimta.smtp.server to implement an edge service to receive messages.

  • listener(ip, port) tuple to listen on, as described in EdgeServer.

  • queueQueue object for handing off messages, as described in handoff().

  • pool – Optional greenlet pool, as described in Edge.

  • max_size – Maximum size of incoming messages.

  • validator_classSmtpValidators sub-class to validate commands and alter replies.

  • auth – If True, enable authentication with default mechanisms. May also be given as a list of SASL mechanism names to support, e.g. ['PLAIN', 'LOGIN', 'CRAM-MD5'].

  • context (SSLContext) – Enables SSL encryption on connected sockets using the information given in the context.

  • tls_immediately – If True, connections will be encrypted immediately before the SMTP banner, rather than advertising the STARTTLS extension.

  • command_timeout – Seconds before the connection times out waiting for a command.

  • data_timeout – Seconds before the connection times out while receiving data. This is a cumulative timeout that is not tricked by the client sending data.

  • hostname – String identifying the local machine. See Edge for more details.

  • session_class – Optional SmtpSession sub-class to be used instead of the default one.

handle(socket, address)

Override this function to receive messages on the socket and call handoff() with each received Envelope object.

  • socket – The socket for the connected client.

  • address – The address of the connected client.



class slimta.edge.smtp.SmtpValidators(session)

Bases: object

Base class for implementing SMTP command validators.

Sub-classes may implement some or all of the following functions. Leaving the reply argument untouched will return the default, successful reply from the command. Setting the response code to 421 or 221 will close the connection.

See also

RFC 2821 4.2

  • handle_banner(reply, address): Validate connecting address before sending the SMTP banner.

  • handle_ehlo(reply, ehlo_as): Validate the EHLO string.

  • handle_helo(reply, helo_as): Validate the HELO string.

  • handle_auth(reply, creds): Validate an authentication attempt, given a AuthenticationCredentials object.

  • handle_mail(reply, sender, params): Validate the sender address.

  • handle_rcpt(reply, recipient, params): Validate one recipient address.

  • handle_data(reply): Any remaining validation before receiving data.

  • handle_have_data(reply, data): Validate the received message data.

  • handle_queued(reply, results): Once the message has been queued, modify the returned Reply using the results from calling enqueue().

  • handle_rset(reply): Called before replying to an RSET command.

  • handle_tls(): Called after a successful TLS handshake. This may be at the beginning of the session or after a STARTTLS command.

  • handle_tls2(ssl_socket): Identical to handle_tls() except the new SSLSocket is passed in as an argument.


session – When sub-classes are instantiated, instances are passed this object, stored and described in session below, that have useful information about the current session.


This instance attribute is an object that has its own set of attributes which may be useful in validation:

  • address: The address tuple of the connecting client.

  • extended_smtp: The client used EHLO instead of HELO.

  • security: Security of connection, None or 'TLS'.

  • ehlo_as: The EHLO or HELO string given by the client.

  • auth: A tuple of the form (authcid, authzid) if the

    client has authenticated.

  • envelope: The Envelope being pieced together to send by the

    connecting client.