Ticket #13142: smtp_add_ssl-v0.2.diff

File smtp_add_ssl-v0.2.diff, 1.9 KB (added by Sergey Tereschenko, 15 years ago)

this patch with checking python version

  • smtp.py

    old new  
    33import smtplib
    44import socket
    55import threading
     6from sys import version_info
    67
    78from django.conf import settings
    89from django.core.mail.backends.base import BaseEmailBackend
     
    1314    A wrapper that manages the SMTP network connection.
    1415    """
    1516    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):
    1718        super(EmailBackend, self).__init__(fail_silently=fail_silently)
    1819        self.host = host or settings.EMAIL_HOST
    1920        self.port = port or settings.EMAIL_PORT
    2021        self.username = username or settings.EMAIL_HOST_USER
    2122        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
    2227        if use_tls is None:
    2328            self.use_tls = settings.EMAIL_USE_TLS
    2429        else:
     
    3742        try:
    3843            # If local_hostname is not specified, socket.getfqdn() gets used.
    3944            # 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())
    4251            if self.use_tls:
    4352                self.connection.ehlo()
    4453                self.connection.starttls()
Back to Top