Skip to content
30 changes: 22 additions & 8 deletions Doc/library/smtplib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
.. class:: SMTP(host='', port=0, local_hostname=None[, timeout], source_address=None)

An :class:`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 :meth:`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
that support a full repertoire of SMTP and ESMTP operations.
If the host parameter is set to a truthy value, :meth:`SMTP.connect` is
called automatically when the object is created, otherwise :meth:`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
:func:`socket.getfqdn`. If the :meth:`connect` call returns anything other
than a success code, an :exc:`SMTPConnectError` is raised. The optional
Expand Down Expand Up @@ -62,6 +64,10 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
``smtplib.SMTP.send`` with arguments ``self`` and ``data``,
where ``data`` is the bytes about to be sent to the remote host.

.. attribute:: SMTP.default_port

The default port used for SMTP connections (25).

.. versionchanged:: 3.3
Support for the :keyword:`with` statement was added.

Expand All @@ -80,15 +86,21 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).

An :class:`SMTP_SSL` instance behaves exactly the same as instances of
:class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is
required from the beginning of the connection and using :meth:`~SMTP.starttls`
is not appropriate. If *host* is not specified, the local host is used. If
*port* is zero, the standard SMTP-over-SSL port (465) is used. The optional
arguments *local_hostname*, *timeout* and *source_address* have the same
required from the beginning of the connection and using :meth:`SMTP.starttls` is
not appropriate. If the host parameter is set to a truthy value,
:meth:`SMTP.connect` is called automatically when the object is created,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, I'd prefer connect(host, port) (or "connect is called with host and port")

otherwise :meth:`!SMTP.connect` must be called manually.

The optional arguments *local_hostname*, *timeout* and *source_address* have the same
meaning as they do in the :class:`SMTP` class. *context*, also optional,
can contain a :class:`~ssl.SSLContext` and allows configuring various
aspects of the secure connection. Please read :ref:`ssl-security` for
best practices.

.. attribute:: SMTP_SSL.default_port

The default port used for SMTP-over-SSL connections (465).

.. versionchanged:: 3.3
*context* was added.

Expand Down Expand Up @@ -259,6 +271,8 @@ An :class:`SMTP` instance has the following methods:
2-tuple of the response code and message sent by the server in its
connection response.

If the port is not specified, the value of the :attr:`default_port` attribute is used.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If port is not changed from its default value of 0"


.. audit-event:: smtplib.connect self,host,port smtplib.SMTP.connect


Expand Down
Loading