From 7a489c3e5899beefb5a25a181fa1b617ace32942 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Tue, 15 Mar 2011 15:04:44 -0400 Subject: - Issue #11289: `smtp.SMTP` class becomes a context manager so it can be used in a `with` statement. Contributed by Giampaolo Rodola. --- Doc/library/smtplib.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'Doc/library/smtplib.rst') diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index 531a64d73f..4805c8e205 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -34,6 +34,20 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). For normal use, you should only require the initialization/connect, :meth:`sendmail`, and :meth:`quit` methods. An example is included below. + The :class:`SMTP` class supports the :keyword:`with` statement. When used + like this, the SMTP ``QUIT`` command is issued automatically when the + :keyword:`with` statement exits. E.g.:: + + >>> from smtplib import SMTP + >>> with SMTP("domain.org") as smtp: + ... smtp.noop() + ... + (250, b'Ok') + >>> + + .. versionadded:: 3.3 + Support for the :keyword:`with` statement was added. + .. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout]) -- cgit v1.2.1 From 07a30b3859180e5a529c7f3370860a7617a65d3e Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 26 Apr 2011 18:53:42 +0200 Subject: I think this should be "versionchanged", not "versionadded" --- Doc/library/smtplib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Doc/library/smtplib.rst') diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index 4805c8e205..cfd5018a99 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -45,7 +45,7 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). (250, b'Ok') >>> - .. versionadded:: 3.3 + .. versionchanged:: 3.3 Support for the :keyword:`with` statement was added. -- cgit v1.2.1 From 7c5cdad4d1b06d46395b80624e9815d1afcd1096 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 18 May 2011 18:03:09 +0200 Subject: Issue #8809: The SMTP_SSL constructor and SMTP.starttls() now support passing a `context` argument pointing to an ssl.SSLContext instance. Patch by Kasun Herath. --- Doc/library/smtplib.rst | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Doc/library/smtplib.rst') diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index cfd5018a99..b432d3ec16 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -49,7 +49,7 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). Support for the :keyword:`with` statement was added. -.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout]) +.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout], context=None) A :class:`SMTP_SSL` instance behaves exactly the same as instances of :class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is @@ -57,11 +57,16 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). 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. *keyfile* and *certfile* are also optional, and can contain a PEM formatted private key - and certificate chain file for the SSL connection. The optional *timeout* + and certificate chain file for the SSL connection. *context* also optional, can contain + a SSLContext, and is an alternative to keyfile and certfile; If it is specified both + keyfile and certfile must be None. 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). + .. versionchanged:: 3.3 + *context* was added. + .. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None) @@ -256,7 +261,7 @@ An :class:`SMTP` instance has the following methods: No suitable authentication method was found. -.. method:: SMTP.starttls(keyfile=None, certfile=None) +.. method:: SMTP.starttls(keyfile=None, certfile=None, context=None) Put the SMTP connection in TLS (Transport Layer Security) mode. All SMTP commands that follow will be encrypted. You should then call :meth:`ehlo` @@ -265,6 +270,9 @@ An :class:`SMTP` instance has the following methods: If *keyfile* and *certfile* are provided, these are passed to the :mod:`socket` module's :func:`ssl` function. + Optional *context* parameter is a :class:`ssl.SSLContext` object; This is an alternative to + using a keyfile and a certfile and if specified both *keyfile* and *certfile* should be None. + If there has been no previous ``EHLO`` or ``HELO`` command this session, this method tries ESMTP ``EHLO`` first. @@ -277,6 +285,9 @@ An :class:`SMTP` instance has the following methods: :exc:`RuntimeError` SSL/TLS support is not available to your Python interpreter. + .. versionchanged:: 3.3 + *context* was added. + .. method:: SMTP.sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_options=[]) -- cgit v1.2.1 From f050c5d357e3b517ce9c0c1c4fdef6192952e657 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sat, 30 Jul 2011 10:56:50 +0800 Subject: Fix closes Issue11281 - smtplib.STMP gets source_address parameter, which adds the ability to bind to specific source address on a machine with multiple interfaces. Patch by Paulo Scardine. --- Doc/library/smtplib.rst | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'Doc/library/smtplib.rst') diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index 24aff0589b..afe6b7b824 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -20,7 +20,7 @@ details of SMTP and ESMTP operation, consult :rfc:`821` (Simple Mail Transfer Protocol) and :rfc:`1869` (SMTP Service Extensions). -.. class:: SMTP(host='', port=0, local_hostname=None[, timeout]) +.. class:: SMTP(host='', port=0, local_hostname=None[, timeout], source_address=None) A :class:`SMTP` instance encapsulates an SMTP connection. It has methods that support a full repertoire of SMTP and ESMTP operations. If the optional @@ -29,7 +29,12 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). raised if the specified host doesn't respond correctly. 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). + setting will be used). The optional source_address parameter allows to bind 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 + ommited (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, :meth:`sendmail`, and :meth:`quit` methods. An example is included below. @@ -48,8 +53,10 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). .. versionchanged:: 3.3 Support for the :keyword:`with` statement was added. + .. versionadded:: 3.3 + source_address parameter. -.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout], context=None) +.. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout], context=None, source_address=None) A :class:`SMTP_SSL` instance behaves exactly the same as instances of :class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is @@ -62,18 +69,28 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). keyfile and certfile must be None. 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). + will be used). The optional source_address parameter allows to bind 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 + ommited (or if host or port are '' and/or 0 respectively) the OS default + behavior will be used. .. versionchanged:: 3.3 *context* was added. + .. versionadded:: 3.3 + source_address parameter. -.. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None) + +.. class:: 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 :meth:`connect` - method must support that as well as a regular host:port server. To specify a - Unix socket, you must use an absolute path for *host*, starting with a '/'. + standard SMTP client. It's common to use Unix sockets for LMTP, so our + :meth:`connect` method must support that as well as a regular host:port + server. The optional parameters local_hostname and source_address has the + same meaning as that of SMTP client.To specify a Unix socket, you must use + an absolute path for *host*, starting with a '/'. Authentication is supported, using the regular SMTP mechanism. When using a Unix socket, LMTP generally don't support or require any authentication, but your -- cgit v1.2.1 From 1ae588e33d13a035767ac51008c593ebbafb81fd Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sat, 30 Jul 2011 10:58:30 +0800 Subject: fixing the smtplib.rst whitespaces. --- Doc/library/smtplib.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Doc/library/smtplib.rst') diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index afe6b7b824..4a0f75677a 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -90,7 +90,7 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). :meth:`connect` method must support that as well as a regular host:port server. The optional parameters local_hostname and source_address has the same meaning as that of SMTP client.To specify a Unix socket, you must use - an absolute path for *host*, starting with a '/'. + an absolute path for *host*, starting with a '/'. Authentication is supported, using the regular SMTP mechanism. When using a Unix socket, LMTP generally don't support or require any authentication, but your -- cgit v1.2.1 From 18436484230f7c9563d98aab2d693e21a263b467 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sun, 31 Jul 2011 09:14:17 +0800 Subject: Addressing the review comments by Antoine Pitrou for smtplib.py and test_smtplib.py. Review comments by Ezio Melotti for smtplib.rst --- Doc/library/smtplib.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Doc/library/smtplib.rst') diff --git a/Doc/library/smtplib.rst b/Doc/library/smtplib.rst index 4a0f75677a..7dd038d292 100644 --- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -31,9 +31,9 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). like the connection attempt (if not specified, the global default timeout setting will be used). The optional source_address parameter allows to bind 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), + 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 - ommited (or if host or port are '' and/or 0 respectively) the OS default + 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, @@ -53,8 +53,8 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). .. versionchanged:: 3.3 Support for the :keyword:`with` statement was added. - .. versionadded:: 3.3 - source_address parameter. + .. versionchanged:: 3.3 + source_address argument was added. .. class:: SMTP_SSL(host='', port=0, local_hostname=None, keyfile=None, certfile=None[, timeout], context=None, source_address=None) @@ -73,14 +73,14 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). 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 - ommited (or if host or port are '' and/or 0 respectively) the OS default + omitted (or if host or port are ``''`` and/or 0 respectively) the OS default behavior will be used. .. versionchanged:: 3.3 *context* was added. - .. versionadded:: 3.3 - source_address parameter. + .. versionchanged:: 3.3 + source_address argument was added. .. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None, source_address=None) @@ -88,8 +88,8 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions). 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 :meth:`connect` method must support that as well as a regular host:port - server. The optional parameters local_hostname and source_address has the - same meaning as that of SMTP client.To specify a Unix socket, you must use + server. The optional arguments local_hostname and source_address have the + same meaning as that of SMTP client. To specify a Unix socket, you must use an absolute path for *host*, starting with a '/'. Authentication is supported, using the regular SMTP mechanism. When using a Unix -- cgit v1.2.1