Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #3007 -- Fixed Python 2.4-ism from [4051] in django/core/mail.p…

…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...
commit 4b4efced54ecef304348545001f44cad27ad06e6 1 parent fdb3b73
@adrianholovaty adrianholovaty authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 django/core/mail.py
View
8 django/core/mail.py
@@ -8,6 +8,8 @@
import time
import random
+DNS_NAME = socket.getfqdn() # Cache the hostname
+
class BadHeaderError(ValueError):
pass
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.