Code

Ticket #13142: smtp_ssl_final.diff

File smtp_ssl_final.diff, 3.8 KB (added by Wojciech Banaś <fizista@…>, 3 years ago)

patch with documentation and default settings

Line 
1Index: docs/topics/email.txt
2===================================================================
3--- docs/topics/email.txt       (wersja 17163)
4+++ docs/topics/email.txt       (kopia robocza)
5@@ -27,7 +27,7 @@
6 :setting:`EMAIL_HOST` and :setting:`EMAIL_PORT` settings. The
7 :setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD` settings, if
8 set, are used to authenticate to the SMTP server, and the
9-:setting:`EMAIL_USE_TLS` setting controls whether a secure connection is used.
10+:setting:`EMAIL_USE_TLS` or :setting:`EMAIL_USE_SSL` setting controls whether a secure connection is used.
11 
12 .. note::
13 
14Index: docs/ref/settings.txt
15===================================================================
16--- docs/ref/settings.txt       (wersja 17163)
17+++ docs/ref/settings.txt       (kopia robocza)
18@@ -977,6 +977,19 @@
19 
20 Whether to use a TLS (secure) connection when talking to the SMTP server.
21 
22+.. setting:: EMAIL_USE_SSL
23+
24+EMAIL_USE_SSL
25+-------------
26+
27+Default: ``False``
28+
29+Whether to use a SSL (secure) connection when talking to the SMTP server.
30+
31+.. warning::
32+
33+       Requirements: Python 2.6 or higher
34+
35 .. setting:: FILE_CHARSET
36 
37 FILE_CHARSET
38@@ -1027,7 +1040,7 @@
39 
40 .. warning::
41 
42-    **Always prefix the mode with a 0.**
43+       **Always prefix the mode with a 0.**
44 
45     If you're not familiar with file modes, please note that the leading
46     ``0`` is very important: it indicates an octal number, which is the
47Index: django/conf/global_settings.py
48===================================================================
49--- django/conf/global_settings.py      (wersja 17163)
50+++ django/conf/global_settings.py      (kopia robocza)
51@@ -171,6 +171,7 @@
52 EMAIL_HOST_USER = ''
53 EMAIL_HOST_PASSWORD = ''
54 EMAIL_USE_TLS = False
55+EMAIL_USE_SSL = False
56 
57 # List of strings representing installed apps.
58 INSTALLED_APPS = ()
59Index: django/core/mail/backends/smtp.py
60===================================================================
61--- django/core/mail/backends/smtp.py   (wersja 17163)
62+++ django/core/mail/backends/smtp.py   (kopia robocza)
63@@ -2,6 +2,7 @@
64 import smtplib
65 import socket
66 import threading
67+from sys import version_info
68 
69 from django.conf import settings
70 from django.core.mail.backends.base import BaseEmailBackend
71@@ -14,7 +15,7 @@
72     A wrapper that manages the SMTP network connection.
73     """
74     def __init__(self, host=None, port=None, username=None, password=None,
75-                 use_tls=None, fail_silently=False, **kwargs):
76+                 use_ssl=None, use_tls=None, fail_silently=False, **kwargs):
77         super(EmailBackend, self).__init__(fail_silently=fail_silently)
78         self.host = host or settings.EMAIL_HOST
79         self.port = port or settings.EMAIL_PORT
80@@ -26,6 +27,10 @@
81             self.password = settings.EMAIL_HOST_PASSWORD
82         else:
83             self.password = password
84+        if use_ssl is None:
85+            if settings.EMAIL_USE_SSL and version_info < (2, 6):
86+                self.use_ssl = False
87+            self.use_ssl = settings.EMAIL_USE_SSL
88         if use_tls is None:
89             self.use_tls = settings.EMAIL_USE_TLS
90         else:
91@@ -44,8 +49,12 @@
92         try:
93             # If local_hostname is not specified, socket.getfqdn() gets used.
94             # For performance, we use the cached FQDN for local_hostname.
95-            self.connection = smtplib.SMTP(self.host, self.port,
96-                                           local_hostname=DNS_NAME.get_fqdn())
97+            if self.use_ssl:
98+                self.connection = smtplib.SMTP_SSL(self.host, self.port,
99+                        local_hostname=DNS_NAME.get_fqdn())
100+            else:
101+                self.connection = smtplib.SMTP(self.host, self.port,
102+                        local_hostname=DNS_NAME.get_fqdn())
103             if self.use_tls:
104                 self.connection.ehlo()
105                 self.connection.starttls()