Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 36beb66

Browse files
committed
#18179: document the local_hostname parameter.
Original patch by Berker Peksag.
1 parent e19ee85 commit 36beb66

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

Doc/library/smtplib.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
2525
A :class:`SMTP` instance encapsulates an SMTP connection. It has methods
2626
that support a full repertoire of SMTP and ESMTP operations. If the optional
2727
host and port parameters are given, the SMTP :meth:`connect` method is called
28-
with those parameters during initialization. If the :meth:`connect` call
28+
with those parameters during initialization. If specified, *local_hostname* is
29+
used as the FQDN of the local host in the HELO/EHLO command. Otherwise, the
30+
local hostname is found using :func:`socket.getfqdn`. If the
31+
:meth:`connect` call
2932
returns anything other than a success code, an :exc:`SMTPConnectError` is
3033
raised. The optional *timeout* parameter specifies a timeout in seconds for
3134
blocking operations like the connection attempt (if not specified, the
@@ -57,13 +60,17 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
5760
.. versionchanged:: 3.3
5861
source_address argument was added.
5962

60-
.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout], context=None, source_address=None)
63+
.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, \
64+
certfile=None [, timeout], context=None, \
65+
source_address=None)
6166

6267
A :class:`SMTP_SSL` instance behaves exactly the same as instances of
6368
:class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is
6469
required from the beginning of the connection and using :meth:`starttls` is
6570
not appropriate. If *host* is not specified, the local host is used. If
66-
*port* is zero, the standard SMTP-over-SSL port (465) is used. *keyfile*
71+
*port* is zero, the standard SMTP-over-SSL port (465) is used. The optional
72+
arguments *local_hostname* and *source_address* have the same meaning as
73+
they do in the :class:`SMTP` class. *keyfile*
6774
and *certfile* are also optional, and can contain a PEM formatted private key
6875
and certificate chain file for the SSL connection. *context* also optional, can contain
6976
a SSLContext, and is an alternative to keyfile and certfile; If it is specified both
@@ -90,7 +97,7 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
9097
standard SMTP client. It's common to use Unix sockets for LMTP, so our
9198
:meth:`connect` method must support that as well as a regular host:port
9299
server. The optional arguments local_hostname and source_address have the
93-
same meaning as that of SMTP client. To specify a Unix socket, you must use
100+
same meaning as they do in the :class:`SMTP` class. To specify a Unix socket, you must use
94101
an absolute path for *host*, starting with a '/'.
95102

96103
Authentication is supported, using the regular SMTP mechanism. When using a Unix

Lib/smtplib.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ def __init__(self, host='', port=0, local_hostname=None,
224224
By default, smtplib.SMTP_PORT is used. If a host is specified the
225225
connect method is called, and if it returns anything other than
226226
a success code an SMTPConnectError is raised. If specified,
227-
`local_hostname` is used as the FQDN of the local host. By default,
227+
`local_hostname` is used as the FQDN of the local host in the
228+
HELO/EHLO command. Otherwise,
228229
the local hostname is found using socket.getfqdn(). The
229230
`source_address` parameter takes a 2-tuple (host, port) for the socket
230231
to bind to as its source address before connecting. If the host is ''
@@ -855,8 +856,8 @@ class SMTP_SSL(SMTP):
855856
""" This is a subclass derived from SMTP that connects over an SSL encrypted
856857
socket (to use this class you need a socket module that was compiled with SSL
857858
support). If host is not specified, '' (the local host) is used. If port is
858-
omitted, the standard SMTP-over-SSL port (465) is used. The optional
859-
source_address takes a two-tuple (host,port) for socket to bind to. keyfile and certfile
859+
omitted, the standard SMTP-over-SSL port (465) is used. local_hostname and
860+
source_address have the same meaning as they do in the SMTP class. keyfile and certfile
860861
are also optional - they can contain a PEM formatted private key and
861862
certificate chain file for the SSL connection. context also optional, can contain
862863
a SSLContext, and is an alternative to keyfile and certfile; If it is specified both
@@ -905,7 +906,9 @@ class LMTP(SMTP):
905906
The LMTP protocol, which is very similar to ESMTP, is heavily based
906907
on the standard SMTP client. It's common to use Unix sockets for LMTP,
907908
so our connect() method must support that as well as a regular
908-
host:port server. To specify a Unix socket, you must use an absolute
909+
host:port server. local_hostname and source_address have the same
910+
meaning as they do in the SMTP class.
911+
To specify a Unix socket, you must use an absolute
909912
path as the host, starting with a '/'.
910913
911914
Authentication is supported, using the regular SMTP mechanism. When

0 commit comments

Comments
 (0)