Ticket #13142: smtp_ssl_final.diff

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

patch with documentation and default settings

  • docs/topics/email.txt

     
    2727:setting:`EMAIL_HOST` and :setting:`EMAIL_PORT` settings. The
    2828:setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD` settings, if
    2929set, are used to authenticate to the SMTP server, and the
    30 :setting:`EMAIL_USE_TLS` setting controls whether a secure connection is used.
     30:setting:`EMAIL_USE_TLS` or :setting:`EMAIL_USE_SSL` setting controls whether a secure connection is used.
    3131
    3232.. note::
    3333
  • docs/ref/settings.txt

     
    977977
    978978Whether to use a TLS (secure) connection when talking to the SMTP server.
    979979
     980.. setting:: EMAIL_USE_SSL
     981
     982EMAIL_USE_SSL
     983-------------
     984
     985Default: ``False``
     986
     987Whether to use a SSL (secure) connection when talking to the SMTP server.
     988
     989.. warning::
     990
     991        Requirements: Python 2.6 or higher
     992
    980993.. setting:: FILE_CHARSET
    981994
    982995FILE_CHARSET
     
    10271040
    10281041.. warning::
    10291042
    1030     **Always prefix the mode with a 0.**
     1043        **Always prefix the mode with a 0.**
    10311044
    10321045    If you're not familiar with file modes, please note that the leading
    10331046    ``0`` is very important: it indicates an octal number, which is the
  • django/conf/global_settings.py

     
    171171EMAIL_HOST_USER = ''
    172172EMAIL_HOST_PASSWORD = ''
    173173EMAIL_USE_TLS = False
     174EMAIL_USE_SSL = False
    174175
    175176# List of strings representing installed apps.
    176177INSTALLED_APPS = ()
  • django/core/mail/backends/smtp.py

     
    22import smtplib
    33import socket
    44import threading
     5from sys import version_info
    56
    67from django.conf import settings
    78from django.core.mail.backends.base import BaseEmailBackend
     
    1415    A wrapper that manages the SMTP network connection.
    1516    """
    1617    def __init__(self, host=None, port=None, username=None, password=None,
    17                  use_tls=None, fail_silently=False, **kwargs):
     18                 use_ssl=None, use_tls=None, fail_silently=False, **kwargs):
    1819        super(EmailBackend, self).__init__(fail_silently=fail_silently)
    1920        self.host = host or settings.EMAIL_HOST
    2021        self.port = port or settings.EMAIL_PORT
     
    2627            self.password = settings.EMAIL_HOST_PASSWORD
    2728        else:
    2829            self.password = password
     30        if use_ssl is None:
     31            if settings.EMAIL_USE_SSL and version_info < (2, 6):
     32                self.use_ssl = False
     33            self.use_ssl = settings.EMAIL_USE_SSL
    2934        if use_tls is None:
    3035            self.use_tls = settings.EMAIL_USE_TLS
    3136        else:
     
    4449        try:
    4550            # If local_hostname is not specified, socket.getfqdn() gets used.
    4651            # For performance, we use the cached FQDN for local_hostname.
    47             self.connection = smtplib.SMTP(self.host, self.port,
    48                                            local_hostname=DNS_NAME.get_fqdn())
     52            if self.use_ssl:
     53                self.connection = smtplib.SMTP_SSL(self.host, self.port,
     54                        local_hostname=DNS_NAME.get_fqdn())
     55            else:
     56                self.connection = smtplib.SMTP(self.host, self.port,
     57                        local_hostname=DNS_NAME.get_fqdn())
    4958            if self.use_tls:
    5059                self.connection.ehlo()
    5160                self.connection.starttls()
Back to Top