cpython: 6737de76487b (original) (raw)

Mercurial > cpython

changeset 70185:6737de76487b

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. [#8809]

Antoine Pitrou solipsis@pitrou.net
date Wed, 18 May 2011 18:03:09 +0200
parents c52807b17e03
children ebe93fec1558
files Doc/library/smtplib.rst Lib/smtplib.py Lib/test/test_smtpnet.py Misc/NEWS
diffstat 4 files changed, 70 insertions(+), 9 deletions(-)[+] [-] Doc/library/smtplib.rst 17 Lib/smtplib.py 31 Lib/test/test_smtpnet.py 27 Misc/NEWS 4

line wrap: on

line diff

--- a/Doc/library/smtplib.rst +++ b/Doc/library/smtplib.rst @@ -49,7 +49,7 @@ Protocol) and :rfc:1869 (SMTP Service 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 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

+ .. class:: LMTP(host='', port=LMTP_PORT, local_hostname=None) @@ -256,7 +261,7 @@ An :class:SMTP instance has the follow 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 follow If keyfile and certfile are provided, these are passed to the :mod:socket module's :func:ssl function.

@@ -277,6 +285,9 @@ An :class:SMTP instance has the follow :exc:RuntimeError SSL/TLS support is not available to your Python interpreter.

+ .. method:: SMTP.sendmail(from_addr, to_addrs, msg, mail_options=[], rcpt_options=[])

--- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -635,7 +635,7 @@ class SMTP: # We could not login sucessfully. Return result of last attempt. raise SMTPAuthenticationError(code, resp)

If there has been no previous EHLO or HELO command this session, this @@ -659,7 +659,16 @@ class SMTP: if resp == 220: if not _have_ssl: raise RuntimeError("No SSL support included in this Python")

@@ -815,23 +824,35 @@ if _have_ssl: support). If host is not specified, '' (the local host) is used. If port is omitted, the standard SMTP-over-SSL port (465) is used. keyfile and certfile are also optional - they can contain a PEM formatted private key and

default_port = SMTP_SSL_PORT def init(self, host='', port=0, local_hostname=None, keyfile=None, certfile=None,

def _get_socket(self, host, port, timeout): if self.debuglevel > 0: print('connect:', (host, port), file=stderr) new_socket = socket.create_connection((host, port), timeout)

--- a/Lib/test/test_smtpnet.py +++ b/Lib/test/test_smtpnet.py @@ -3,12 +3,29 @@ import unittest from test import support import smtplib +import ssl support.requires("network") + +class SmtpTest(unittest.TestCase):

+

+ + class SmtpSSLTest(unittest.TestCase): testServer = 'smtp.gmail.com' remotePort = 465

def test_connect(self): support.get_attribute(smtplib, 'SMTP_SSL') @@ -24,8 +41,16 @@ class SmtpSSLTest(unittest.TestCase): server.ehlo() server.quit()

+ + def test_main():

if name == "main": test_main()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -153,6 +153,10 @@ Core and Builtins Library ------- +- Issue #8809: The SMTP_SSL constructor and SMTP.starttls() now support