Ticket #3713: mail.diff
File mail.diff, 1.5 KB (added by , 18 years ago) |
---|
-
django/core/mail.py
5 5 from email.Header import Header 6 6 from email.Utils import formatdate 7 7 import smtplib 8 import socket9 import time10 import random11 8 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() 9 try: 10 from email.Utils import make_msgid 11 except ImportError: 12 from email.utils import make_msgid 17 13 18 def get_fqdn(self):19 if not hasattr(self, '_fqdn'):20 self._fqdn = socket.getfqdn()21 return self._fqdn22 23 DNS_NAME = CachedDnsName()24 25 14 class BadHeaderError(ValueError): 26 15 pass 27 16 … … 80 69 msg['From'] = from_email 81 70 msg['To'] = ', '.join(recipient_list) 82 71 msg['Date'] = formatdate() 72 msg['Message-ID'] = make_msgid() 83 73 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:89 74 server.sendmail(from_email, recipient_list, msg.as_string()) 90 75 num_sent += 1 91 76 except: