Ticket #13142: smtp_add_ssl-v0.2.diff
File smtp_add_ssl-v0.2.diff, 1.9 KB (added by , 15 years ago) |
---|
-
smtp.py
old new 3 3 import smtplib 4 4 import socket 5 5 import threading 6 from sys import version_info 6 7 7 8 from django.conf import settings 8 9 from django.core.mail.backends.base import BaseEmailBackend … … 13 14 A wrapper that manages the SMTP network connection. 14 15 """ 15 16 def __init__(self, host=None, port=None, username=None, password=None, 16 use_ tls=None, fail_silently=False, **kwargs):17 use_ssl=None, use_tls=None, fail_silently=False, **kwargs): 17 18 super(EmailBackend, self).__init__(fail_silently=fail_silently) 18 19 self.host = host or settings.EMAIL_HOST 19 20 self.port = port or settings.EMAIL_PORT 20 21 self.username = username or settings.EMAIL_HOST_USER 21 22 self.password = password or settings.EMAIL_HOST_PASSWORD 23 if use_ssl is None: 24 if settings.EMAIL_USE_SSL and version_info < (2, 6): 25 self.use_ssl = False 26 self.use_ssl = settings.EMAIL_USE_SSL 22 27 if use_tls is None: 23 28 self.use_tls = settings.EMAIL_USE_TLS 24 29 else: … … 37 42 try: 38 43 # If local_hostname is not specified, socket.getfqdn() gets used. 39 44 # For performance, we use the cached FQDN for local_hostname. 40 self.connection = smtplib.SMTP(self.host, self.port, 41 local_hostname=DNS_NAME.get_fqdn()) 45 if self.use_ssl: 46 self.connection = smtplib.SMTP_SSL(self.host, self.port, 47 local_hostname=DNS_NAME.get_fqdn()) 48 else: 49 self.connection = smtplib.SMTP(self.host, self.port, 50 local_hostname=DNS_NAME.get_fqdn()) 42 51 if self.use_tls: 43 52 self.connection.ehlo() 44 53 self.connection.starttls()