PyDocs

Nav

Internet Protocols and Support

SMTP

smtplib

class · Added in 3.5 (source) not WASI
  • SMTP(host='', port=0, local_hostname=None, [timeout, ]source_address=None)
This class manages a connection to an SMTP or ESMTP server.
SMTP Objects:
    SMTP objects have the following attributes:
        helo_resp
            This is the message given by the server in response to the
            most recent HELO command.

        ehlo_resp
            This is the message given by the server in response to the
            most recent EHLO command. This is usually multiline.

        does_esmtp
            This is a True value _after you do an EHLO command_, if the
            server supports ESMTP.

        esmtp_features
            This is a dictionary, which, if the server supports ESMTP,
            will _after you do an EHLO command_, contain the names of the
            SMTP service extensions this server supports, and their
            parameters (if any).

            Note, all extension names are mapped to lower case in the
            dictionary.

    See each method's docstrings for details.  In general, there is a
    method of the same name to perform each SMTP command.  There is also a
    method called 'sendmail' that will do an entire mail transaction.
Changed in 3.3, 3.9
  • 3.3: Support for the with statement was added.
  • 3.3: source_address argument was added.
  • 3.9: If the timeout parameter is set to be zero, it will raise a ValueError to prevent the creation of a non-blocking socket.
Members of SMTP

a

auth
Authentication command - requires response processing.

c

connect
Connect to a host on a given port.

d

default_port
The default port used for SMTP connections (25).
docmd
Send a command, and return its response code.
does_esmtp
A boolean value indicating whether the server supports ESMTP, see ehlo().

e

ehlo
SMTP 'ehlo' command.
ehlo_or_helo_if_needed
Call self.ehlo() and/or self.helo() if needed.
ehlo_resp
The response to the EHLO command, see ehlo().
esmtp_features
A dictionary of the names of SMTP service extensions supported by the server, see ehlo().

h

has_extn
Does the server support a given SMTP service extension?
helo
SMTP 'helo' command.
helo_resp
The response to the HELO command, see helo().

l

login
Log in on an SMTP server that requires authentication.

q

quit
Terminate the SMTP session.

s

send_message
Converts message to a bytestring and passes it to sendmail.
sendmail
This command performs an entire mail transaction.
set_debuglevel
Set the debug output level.
starttls
Puts the connection to the SMTP server into TLS mode.

v

verify
SMTP 'verify' command -- checks for address validity.
1 Example
>>> from smtplib import SMTP
>>> with SMTP("domain.org") as smtp:
...     smtp.noop()
...
(250, b'Ok')
>>>
from the Python docs
See Also
No see-alsos for smtplib/SMTP
0 Notes
No notes for SMTP