Ticket #17471: ssl_setting_patch.diff
File ssl_setting_patch.diff, 6.8 KB (added by , 13 years ago) |
---|
-
docs/topics/email.txt
27 27 :setting:`EMAIL_HOST` and :setting:`EMAIL_PORT` settings. The 28 28 :setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD` settings, if 29 29 set, are used to authenticate to the SMTP server, and the 30 :setting:`EMAIL_USE_TLS` setting controls whether a secure connection is used. 30 :setting:`EMAIL_USE_TLS` and :setting:`EMAIL_USE_SSL` settings control whether 31 a secure connection is used. 31 32 32 33 .. note:: 33 34 … … 415 416 This is the default backend. Email will be sent through a SMTP server. 416 417 The server address and authentication credentials are set in the 417 418 :setting:`EMAIL_HOST`, :setting:`EMAIL_PORT`, :setting:`EMAIL_HOST_USER`, 418 :setting:`EMAIL_HOST_PASSWORD` and :setting:`EMAIL_USE_TLS` settings in your419 settings file.419 :setting:`EMAIL_HOST_PASSWORD`, :setting:`EMAIL_USE_TLS` and 420 :setting:`EMAIL_USE_SSL` settings in your settings file. 420 421 421 422 The SMTP backend is the default configuration inherited by Django. If you 422 423 want to specify it explicitly, put the following in your settings:: -
docs/ref/settings.txt
976 976 Default: ``False`` 977 977 978 978 Whether to use a TLS (secure) connection when talking to the SMTP server. 979 This is used for explicit TLS connections, generally on port 587. If you are 980 experiencing hanging connections, see the implicit TLS setting 981 :setting:`EMAIL_USE_SSL`. 979 982 983 .. setting:: EMAIL_USE_SSL 984 985 EMAIL_USE_SSL 986 ------------- 987 988 Default: ``False`` 989 990 Whether to use an implicit TLS (secure) connection when talking to the SMTP 991 server. In most email documentation this type of TLS connection is referred 992 to as SSL. It is generally used on port 465. If you are experiencing problems, 993 see the explicit TLS setting :setting:`EMAIL_USE_TLS`. 994 980 995 .. setting:: FILE_CHARSET 981 996 982 997 FILE_CHARSET -
tests/regressiontests/mail/tests.py
6 6 import smtpd 7 7 import sys 8 8 from StringIO import StringIO 9 from smtplib import SMTPException 10 from ssl import SSLError 9 11 import tempfile 10 12 import threading 11 13 … … 674 676 backend = smtp.EmailBackend(username='', password='') 675 677 self.assertEqual(backend.username, '') 676 678 self.assertEqual(backend.password, '') 679 680 @override_settings(EMAIL_USE_TLS=True) 681 def test_email_tls_use_settings(self): 682 backend = smtp.EmailBackend() 683 self.assertTrue(backend.use_tls) 684 685 @override_settings(EMAIL_USE_TLS=True) 686 def test_email_tls_override_settings(self): 687 backend = smtp.EmailBackend(use_tls=False) 688 self.assertFalse(backend.use_tls) 689 690 def test_email_tls_default_disabled(self): 691 backend = smtp.EmailBackend() 692 self.assertFalse(backend.use_tls) 693 694 @override_settings(EMAIL_USE_SSL=True) 695 def test_email_ssl_use_settings(self): 696 backend = smtp.EmailBackend() 697 self.assertTrue(backend.use_ssl) 698 699 @override_settings(EMAIL_USE_SSL=True) 700 def test_email_ssl_override_settings(self): 701 backend = smtp.EmailBackend(use_ssl=False) 702 self.assertFalse(backend.use_ssl) 703 704 def test_email_ssl_default_disabled(self): 705 backend = smtp.EmailBackend() 706 self.assertFalse(backend.use_ssl) 707 708 @override_settings(EMAIL_USE_TLS=True) 709 def test_email_tls_attempts_starttls(self): 710 backend = smtp.EmailBackend() 711 self.assertTrue(backend.use_tls) 712 try: 713 backend.open() 714 self.fail('SMTPException STARTTLS not raised.') 715 except SMTPException, e: 716 self.assertNotEqual(-1, str(e).find('STARTTLS'), "SMTPException wasn't for STARTTLS") 717 718 @override_settings(EMAIL_USE_SSL=True) 719 def test_email_ssl_attempts_ssl_connection(self): 720 backend = smtp.EmailBackend() 721 self.assertTrue(backend.use_ssl) 722 try: 723 backend.open() 724 self.fail('SSLError not raised.') 725 except SSLError, e: 726 pass -
django/conf/global_settings.py
171 171 EMAIL_HOST_USER = '' 172 172 EMAIL_HOST_PASSWORD = '' 173 173 EMAIL_USE_TLS = False 174 EMAIL_USE_SSL = False 174 175 175 176 # List of strings representing installed apps. 176 177 INSTALLED_APPS = () -
django/core/mail/backends/smtp.py
14 14 A wrapper that manages the SMTP network connection. 15 15 """ 16 16 def __init__(self, host=None, port=None, username=None, password=None, 17 use_tls=None, fail_silently=False, **kwargs):17 use_tls=None, fail_silently=False, use_ssl=None, **kwargs): 18 18 super(EmailBackend, self).__init__(fail_silently=fail_silently) 19 19 self.host = host or settings.EMAIL_HOST 20 20 self.port = port or settings.EMAIL_PORT … … 30 30 self.use_tls = settings.EMAIL_USE_TLS 31 31 else: 32 32 self.use_tls = use_tls 33 if use_ssl is None: 34 self.use_ssl = settings.EMAIL_USE_SSL 35 else: 36 self.use_ssl = use_ssl 33 37 self.connection = None 34 38 self._lock = threading.RLock() 35 39 … … 44 48 try: 45 49 # If local_hostname is not specified, socket.getfqdn() gets used. 46 50 # For performance, we use the cached FQDN for local_hostname. 47 self.connection = smtplib.SMTP(self.host, self.port, 51 if self.use_ssl: 52 self.connection = smtplib.SMTP_SSL(self.host, self.port, 48 53 local_hostname=DNS_NAME.get_fqdn()) 49 if self.use_tls: 50 self.connection.ehlo() 51 self.connection.starttls() 52 self.connection.ehlo() 54 else: 55 self.connection = smtplib.SMTP(self.host, self.port, 56 local_hostname=DNS_NAME.get_fqdn()) 57 # TLS/SSL are mutually exclusive, so only attempt TLS over 58 # non-secure connections. 59 if self.use_tls: 60 self.connection.ehlo() 61 self.connection.starttls() 62 self.connection.ehlo() 53 63 if self.username and self.password: 54 64 self.connection.login(self.username, self.password) 55 65 return True