Skip to content

Commit

Permalink
Fixed #3007 -- Fixed Python 2.4-ism from [4051] in django/core/mail.p…
Browse files Browse the repository at this point in the history
…y. Also cached the result of socket.getfqdn(). Thanks for the patch, SmileyChris

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4058 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
adrianholovaty committed Nov 10, 2006
1 parent fdb3b73 commit 4b4efce
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django/core/mail.py
Expand Up @@ -8,6 +8,8 @@
import time
import random

DNS_NAME = socket.getfqdn() # Cache the hostname

class BadHeaderError(ValueError):
pass

Expand Down Expand Up @@ -53,7 +55,11 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST
msg['From'] = from_email
msg['To'] = ', '.join(recipient_list)
msg['Date'] = rfc822.formatdate()
msg['Message-ID'] = "<%d.%d@%s>" % (time.time(), random.getrandbits(64), socket.getfqdn())
try:
random_bits = str(random.getrandbits(64))
except AttributeError: # Python 2.3 doesn't have random.getrandbits().
random_bits = ''.join([random.choice('1234567890') for i in range(19)])
msg['Message-ID'] = "<%d.%d@%s>" % (time.time(), random_bits, DNS_NAME)
try:
server.sendmail(from_email, recipient_list, msg.as_string())
num_sent += 1
Expand Down

0 comments on commit 4b4efce

Please sign in to comment.