From 4b4efced54ecef304348545001f44cad27ad06e6 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 10 Nov 2006 03:28:58 +0000 Subject: [PATCH] Fixed #3007 -- Fixed Python 2.4-ism from [4051] in django/core/mail.py. 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 --- django/core/mail.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/django/core/mail.py b/django/core/mail.py index d1e5d0aa55..1b7817b530 100644 --- a/django/core/mail.py +++ b/django/core/mail.py @@ -8,6 +8,8 @@ import socket 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