Code

Ticket #13142: smtp_add_ssl.diff

File smtp_add_ssl.diff, 1.6 KB (added by serg.partizan@…, 4 years ago)

Patch that adds support for ssl connections

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