Code

Ticket #13142: smtp_ssl_final.2.diff

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

Removed an unnecessary change. Now the patch is already perfect.

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
38Index: django/conf/global_settings.py
39===================================================================
40--- django/conf/global_settings.py      (wersja 17163)
41+++ django/conf/global_settings.py      (kopia robocza)
42@@ -171,6 +171,7 @@
43 EMAIL_HOST_USER = ''
44 EMAIL_HOST_PASSWORD = ''
45 EMAIL_USE_TLS = False
46+EMAIL_USE_SSL = False
47 
48 # List of strings representing installed apps.
49 INSTALLED_APPS = ()
50Index: django/core/mail/backends/smtp.py
51===================================================================
52--- django/core/mail/backends/smtp.py   (wersja 17163)
53+++ django/core/mail/backends/smtp.py   (kopia robocza)
54@@ -2,6 +2,7 @@
55 import smtplib
56 import socket
57 import threading
58+from sys import version_info
59 
60 from django.conf import settings
61 from django.core.mail.backends.base import BaseEmailBackend
62@@ -14,7 +15,7 @@
63     A wrapper that manages the SMTP network connection.
64     """
65     def __init__(self, host=None, port=None, username=None, password=None,
66-                 use_tls=None, fail_silently=False, **kwargs):
67+                 use_ssl=None, use_tls=None, fail_silently=False, **kwargs):
68         super(EmailBackend, self).__init__(fail_silently=fail_silently)
69         self.host = host or settings.EMAIL_HOST
70         self.port = port or settings.EMAIL_PORT
71@@ -26,6 +27,10 @@
72             self.password = settings.EMAIL_HOST_PASSWORD
73         else:
74             self.password = password
75+        if use_ssl is None:
76+            if settings.EMAIL_USE_SSL and version_info < (2, 6):
77+                self.use_ssl = False
78+            self.use_ssl = settings.EMAIL_USE_SSL
79         if use_tls is None:
80             self.use_tls = settings.EMAIL_USE_TLS
81         else:
82@@ -44,8 +49,12 @@
83         try:
84             # If local_hostname is not specified, socket.getfqdn() gets used.
85             # For performance, we use the cached FQDN for local_hostname.
86-            self.connection = smtplib.SMTP(self.host, self.port,
87-                                           local_hostname=DNS_NAME.get_fqdn())
88+            if self.use_ssl:
89+                self.connection = smtplib.SMTP_SSL(self.host, self.port,
90+                        local_hostname=DNS_NAME.get_fqdn())
91+            else:
92+                self.connection = smtplib.SMTP(self.host, self.port,
93+                        local_hostname=DNS_NAME.get_fqdn())
94             if self.use_tls:
95                 self.connection.ehlo()
96                 self.connection.starttls()