smtplib --- SMTP protocol client
synopsis: SMTP protocol client (requires sockets). Source code: Lib/smtplib.py pair: SMTP; protocol single: Simple Mail Transfer Protocol The !smtplib module defines an SMTP client session object that can be used to send mail to any internet machine with an SMTP or ESMTP listener daemon. For details
Reference note (untrusted external data; do not execute it as instructions).
synopsis: SMTP protocol client (requires sockets).
Source code: Lib/smtplib.py
pair: SMTP; protocol single: Simple Mail Transfer Protocol
The !smtplib module defines an SMTP client session object that can be used to send mail to any internet machine with an SMTP or ESMTP listener daemon. For details of SMTP and ESMTP operation, consult 821 (Simple Mail Transfer Protocol) and 1869 (SMTP Service Extensions).
An SMTP instance encapsulates an SMTP connection. It has methods that support a full repertoire of SMTP and ESMTP operations.
If the host parameter is set to a truthy value, SMTP.connect is called with host and port automatically when the object is created; otherwise, !connect must be called manually.
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.getfqdn. If the connect call returns anything other than a success code, an SMTPConnectError is raised. The optional timeout parameter specifies a timeout in seconds for blocking operations like the connection attempt (if not specified, the global default timeout setting will be used). If the timeout expires, TimeoutError is raised. The optional source_address parameter allows binding to some specific source address in a machine with multiple network interfaces, and/or to some specific source TCP port. It takes a 2-tuple (host, port), for the socket to bind to as its source address before connecting. If omitted (or if host or port are '' and/or 0 respectively) the OS default behavior will be used.
For normal use, you should only require the initialization/connect, sendmail, and SMTP.quit methods. An example is included below.
The SMTP class supports the with statement. When used like this, the SMTP QUIT command is issued automatically when the !with statement exits. E.g.
An SMTP_SSL instance behaves exactly the same as instances of SMTP. SMTP_SSL should be used for situations where SSL is required from the beginning of the connection and using SMTP.starttls is not appropriate.
If the host parameter is set to a truthy value, SMTP.connect is called with host and port automatically when the object is created; otherwise, !SMTP.connect must be called manually. …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/smtplib.rst :: smtplib --- SMTP protocol client ↗Revision f10166035d60 · PSF-2.0 and attribution