Code

Ticket #13142: smtp_add_ssl-v0.2.diff

File smtp_add_ssl-v0.2.diff, 1.9 KB (added by partizan, 4 years ago)

this patch with checking python version

Line 
1--- smtp.py.old 2010-03-18 12:15:56.000000000 +0200
2+++ smtp.py     2010-03-18 16:07:05.000000000 +0200
3@@ -3,6 +3,7 @@
4 import smtplib
5 import socket
6 import threading
7+from sys import version_info
8 
9 from django.conf import settings
10 from django.core.mail.backends.base import BaseEmailBackend
11@@ -13,12 +14,16 @@
12     A wrapper that manages the SMTP network connection.
13     """
14     def __init__(self, host=None, port=None, username=None, password=None,
15-                 use_tls=None, fail_silently=False, **kwargs):
16+                 use_ssl=None, use_tls=None, fail_silently=False, **kwargs):
17         super(EmailBackend, self).__init__(fail_silently=fail_silently)
18         self.host = host or settings.EMAIL_HOST
19         self.port = port or settings.EMAIL_PORT
20         self.username = username or settings.EMAIL_HOST_USER
21         self.password = password or settings.EMAIL_HOST_PASSWORD
22+        if use_ssl is None:
23+            if settings.EMAIL_USE_SSL and version_info < (2, 6):
24+                self.use_ssl = False
25+            self.use_ssl = settings.EMAIL_USE_SSL
26         if use_tls is None:
27             self.use_tls = settings.EMAIL_USE_TLS
28         else:
29@@ -37,8 +42,12 @@
30         try:
31             # If local_hostname is not specified, socket.getfqdn() gets used.
32             # For performance, we use the cached FQDN for local_hostname.
33-            self.connection = smtplib.SMTP(self.host, self.port,
34-                                           local_hostname=DNS_NAME.get_fqdn())
35+            if self.use_ssl:
36+                self.connection = smtplib.SMTP_SSL(self.host, self.port,
37+                        local_hostname=DNS_NAME.get_fqdn())
38+            else:
39+                self.connection = smtplib.SMTP(self.host, self.port,
40+                        local_hostname=DNS_NAME.get_fqdn())
41             if self.use_tls:
42                 self.connection.ehlo()
43                 self.connection.starttls()