Ticket #3713: mail.diff

File mail.diff, 1.5 KB (added by Jannis Leidel <jl@…>, 18 years ago)

Uses Python's make_msgid()

  • django/core/mail.py

     
    55from email.Header import Header
    66from email.Utils import formatdate
    77import smtplib
    8 import socket
    9 import time
    10 import random
    118
    12 # Cache the hostname, but do it lazily: socket.getfqdn() can take a couple of
    13 # seconds, which slows down the restart of the server.
    14 class CachedDnsName(object):
    15     def __str__(self):
    16         return self.get_fqdn()
     9try:
     10    from email.Utils import make_msgid
     11except ImportError:
     12    from email.utils import make_msgid
    1713
    18     def get_fqdn(self):
    19         if not hasattr(self, '_fqdn'):
    20             self._fqdn = socket.getfqdn()
    21         return self._fqdn
    22 
    23 DNS_NAME = CachedDnsName()
    24 
    2514class BadHeaderError(ValueError):
    2615    pass
    2716
     
    8069        msg['From'] = from_email
    8170        msg['To'] = ', '.join(recipient_list)
    8271        msg['Date'] = formatdate()
     72        msg['Message-ID'] = make_msgid()
    8373        try:
    84             random_bits = str(random.getrandbits(64))
    85         except AttributeError: # Python 2.3 doesn't have random.getrandbits().
    86             random_bits = ''.join([random.choice('1234567890') for i in range(19)])
    87         msg['Message-ID'] = "<%d.%s@%s>" % (time.time(), random_bits, DNS_NAME)
    88         try:
    8974            server.sendmail(from_email, recipient_list, msg.as_string())
    9075            num_sent += 1
    9176        except:
Back to Top