Ticket #6989: mail-local-hostname2.diff

File mail-local-hostname2.diff, 3.9 KB (added by Jeremy Grosser, 14 years ago)
  • django/conf/global_settings.py

    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index 97b7ac6..7da8fa6 100644
    a b EMAIL_HOST_USER = ''  
    176176EMAIL_HOST_PASSWORD = ''
    177177EMAIL_USE_TLS = False
    178178
     179# Hostname to send in the EHLO message to the SMTP server.
     180EMAIL_LOCAL_HOSTNAME = ''
     181
    179182# List of strings representing installed apps.
    180183INSTALLED_APPS = ()
    181184
  • django/core/mail/backends/smtp.py

    diff --git a/django/core/mail/backends/smtp.py b/django/core/mail/backends/smtp.py
    index bb184ab..9b7304d 100644
    a b class EmailBackend(BaseEmailBackend):  
    1414    A wrapper that manages the SMTP network connection.
    1515    """
    1616    def __init__(self, host=None, port=None, username=None, password=None,
    17                  use_tls=None, fail_silently=False, **kwargs):
     17                 use_tls=None, fail_silently=False, from_host=None, **kwargs):
    1818        super(EmailBackend, self).__init__(fail_silently=fail_silently)
    1919        self.host = host or settings.EMAIL_HOST
    2020        self.port = port or settings.EMAIL_PORT
    2121        self.username = username or settings.EMAIL_HOST_USER
    2222        self.password = password or settings.EMAIL_HOST_PASSWORD
     23
     24        # If from_host and settings.EMAIL_FROM_HOST are not specified,
     25        # socket.getfqdn() gets used. For performance, we use the cached
     26        # FQDN for from_host.
     27        self.from_host = from_host or \
     28                         settings.EMAIL_LOCAL_HOSTNAME or \
     29                         DNS_NAME.get_fqdn()
     30
    2331        if use_tls is None:
    2432            self.use_tls = settings.EMAIL_USE_TLS
    2533        else:
    class EmailBackend(BaseEmailBackend):  
    3644            # Nothing to do if the connection is already open.
    3745            return False
    3846        try:
    39             # If local_hostname is not specified, socket.getfqdn() gets used.
    40             # For performance, we use the cached FQDN for local_hostname.
    4147            self.connection = smtplib.SMTP(self.host, self.port,
    42                                            local_hostname=DNS_NAME.get_fqdn())
     48                                           local_hostname=self.from_host)
    4349            if self.use_tls:
    4450                self.connection.ehlo()
    4551                self.connection.starttls()
  • docs/ref/settings.txt

    diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt
    index 8bf0a4e..47e54d4 100644
    a b Whether to use a TLS (secure) connection when talking to the SMTP server.  
    882882
    883883.. setting:: FILE_CHARSET
    884884
     885EMAIL_LOCAL_HOSTNAME
     886--------------------
     887
     888Default: ``''`` (Empty string)
     889
     890The hostname to send to the SMTP server in the EHLO command. If unset, a
     891cached local DNS name from socket.getfqdn() is used.
     892
    885893FILE_CHARSET
    886894------------
    887895
  • docs/topics/email.txt

    diff --git a/docs/topics/email.txt b/docs/topics/email.txt
    index ea62120..892ab23 100644
    a b Mail is sent using the SMTP host and port specified in the  
    3030:setting:`EMAIL_HOST_USER` and :setting:`EMAIL_HOST_PASSWORD` settings, if
    3131set, are used to authenticate to the SMTP server, and the
    3232:setting:`EMAIL_USE_TLS` setting controls whether a secure connection is used.
     33:setting:`EMAIL_LOCAL_HOSTNAME` specifies the hostname to be sent in the
     34SMTP EHLO command
    3335
    3436.. note::
    3537
    SMTP backend  
    417419This is the default backend. E-mail will be sent through a SMTP server.
    418420The server address and authentication credentials are set in the
    419421:setting:`EMAIL_HOST`, :setting:`EMAIL_PORT`, :setting:`EMAIL_HOST_USER`,
    420 :setting:`EMAIL_HOST_PASSWORD` and :setting:`EMAIL_USE_TLS` settings in your
    421 settings file.
     422:setting:`EMAIL_LOCAL_HOSTNAME`, :setting:`EMAIL_HOST_PASSWORD` and
     423:setting:`EMAIL_USE_TLS` settings in your settings file.
    422424
    423425The SMTP backend is the default configuration inherited by Django. If you
    424426want to specify it explicitly, put the following in your settings::
Back to Top