smtplib.SMTP

class smtplib.SMTP(host='', port=0, local_hostname=None, [timeout, ]source_address=None) An SMTP instance encapsulates an SMTP connection. It has methods that support a full repertoire of SMTP and ESMTP operations. If the optional host and port parameters are given, the SMTP connect() method is called with those parameters during initialization. If specified, local_hostname is used as the FQDN of the local host in the HELO/EHLO command. Otherwise, the local hostname is found using socket.get

smtplib.SMTP.connect()

SMTP.connect(host='localhost', port=0) Connect to a host on a given port. The defaults are to connect to the local host at the standard SMTP port (25). If the hostname ends with a colon (':') followed by a number, that suffix will be stripped off and the number interpreted as the port number to use. This method is automatically invoked by the constructor if a host is specified during instantiation. Returns a 2-tuple of the response code and message sent by the server in its connection respon

smtplib.SMTP.ehlo()

SMTP.ehlo(name='') Identify yourself to an ESMTP server using EHLO. The hostname argument defaults to the fully qualified domain name of the local host. Examine the response for ESMTP option and store them for use by has_extn(). Also sets several informational attributes: the message returned by the server is stored as the ehlo_resp attribute, does_esmtp is set to true or false depending on whether the server supports ESMTP, and esmtp_features will be a dictionary containing the names of the

smtplib.SMTP.auth()

SMTP.auth(mechanism, authobject, *, initial_response_ok=True) Issue an SMTP AUTH command for the specified authentication mechanism, and handle the challenge response via authobject. mechanism specifies which authentication mechanism is to be used as argument to the AUTH command; the valid values are those listed in the auth element of esmtp_features. authobject must be a callable object taking an optional single argument: data = authobject(challenge=None) If optional keyword argument ini

smtplib.SMTP.docmd()

SMTP.docmd(cmd, args='') Send a command cmd to the server. The optional argument args is simply concatenated to the command, separated by a space. This returns a 2-tuple composed of a numeric response code and the actual response line (multiline responses are joined into one long line.) In normal operation it should not be necessary to call this method explicitly. It is used to implement other methods and may be useful for testing private extensions. If the connection to the server is lost w

smtpd.SMTPServer.process_message()

process_message(peer, mailfrom, rcpttos, data, **kwargs) Raise a NotImplementedError exception. Override this in subclasses to do something useful with this message. Whatever was passed in the constructor as remoteaddr will be available as the _remoteaddr attribute. peer is the remote host’s address, mailfrom is the envelope originator, rcpttos are the envelope recipients and data is a string containing the contents of the e-mail (which should be in RFC 5321 format). If the decode_data const

smtplib.LMTP

class smtplib.LMTP(host='', port=LMTP_PORT, local_hostname=None, source_address=None) The LMTP protocol, which is very similar to ESMTP, is heavily based on the standard SMTP client. It’s common to use Unix sockets for LMTP, so our connect() method must support that as well as a regular host:port server. The optional arguments local_hostname and source_address have the same meaning as they do in the SMTP class. To specify a Unix socket, you must use an absolute path for host, starting with a

smtpd.SMTPServer.channel_class

channel_class Override this in subclasses to use a custom SMTPChannel for managing SMTP clients.

smtpd.SMTPChannel.received_data

received_data Holds a string containing all of the data sent by the client during the DATA state, up to but not including the terminating "\r\n.\r\n".

smtpd.SMTPChannel.seen_greeting

seen_greeting Holds a string containing the greeting sent by the client in its “HELO”.