Django

Code

Changeset 5144

Show
Ignore:
Timestamp:
05/03/07 08:35:02 (1 year ago)
Author:
mtredinnick
Message:

Fixed #2897 -- Added support for TLS connections to email handling. This means
servers like Google's SMTP server can now be used for admin emails.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/conf/global_settings.py

    r5072 r5144  
    120120EMAIL_HOST_USER = '' 
    121121EMAIL_HOST_PASSWORD = '' 
     122EMAIL_USE_TLS = False 
    122123 
    123124# List of strings representing installed apps. 
  • django/trunk/django/core/mail.py

    r5143 r5144  
    7171 
    7272    def __init__(self, host=None, port=None, username=None, password=None, 
    73                  fail_silently=False): 
    74         if host is None: 
    75             self.host = settings.EMAIL_HOST 
    76         if port is None: 
    77             self.port = settings.EMAIL_PORT 
    78         if username is None: 
    79                 self.username = settings.EMAIL_HOST_USER 
    80         if password is None: 
    81                 self.password = settings.EMAIL_HOST_PASSWORD 
     73            use_tls=None, fail_silently=False): 
     74        self.host = host or settings.EMAIL_HOST 
     75        self.port = (port is not None) and port or settings.EMAIL_PORT 
     76        self.username = username or settings.EMAIL_HOST_USER 
     77        self.password = password or settings.EMAIL_HOST_PASSWORD 
     78        self.use_tls = (use_tls is not None) and use_tls or settings.EMAIL_USE_TLS 
    8279        self.fail_silently = fail_silently 
    8380        self.connection = None 
     
    9390        try: 
    9491            self.connection = smtplib.SMTP(self.host, self.port) 
     92            if self.use_tls: 
     93                self.connection.ehlo() 
     94                self.connection.starttls() 
     95                self.connection.ehlo() 
    9596            if self.username and self.password: 
    9697                self.connection.login(self.username, self.password) 
     
    105106            try: 
    106107                self.connection.quit() 
     108            except socket.sslerror: 
     109                # This happens when calling quit() on a TLS connection 
     110                # sometimes. 
     111                self.connection.close() 
    107112            except: 
    108113                if self.fail_silently: 
  • django/trunk/docs/email.txt

    r5141 r5144  
    2323Mail will be sent using the SMTP host and port specified in the `EMAIL_HOST`_ 
    2424and `EMAIL_PORT`_ settings. The `EMAIL_HOST_USER`_ and `EMAIL_HOST_PASSWORD`_ 
    25 settings, if set, will be used to authenticate to the SMTP server. 
     25settings, if set, will be used to authenticate to the SMTP server and the 
     26`EMAIL_USE_TLS`_ settings will control whether a secure connection is used. 
    2627 
    2728.. note:: 
     
    3536.. _EMAIL_HOST_USER: ../settings/#email-host-user 
    3637.. _EMAIL_HOST_PASSWORD: ../settings/#email-host-password 
     38.. _EMAIL_USE_TLS: ../settings/#email-use-tls 
    3739 
    3840 
  • django/trunk/docs/settings.txt

    r5129 r5144  
    428428or ``django.core.mail.mail_managers``. You'll probably want to include the 
    429429trailing space. 
     430 
     431EMAIL_USE_TLS 
     432------------- 
     433 
     434Default: ``False`` 
     435 
     436Whether to use a TLS (secure) connection when talking to the SMTP server. 
    430437 
    431438FIXTURE_DIRS