Ticket #3985: mail-additional_headers.2.diff
File mail-additional_headers.2.diff, 2.1 KB (added by , 18 years ago) |
---|
-
core/mail.py
34 34 val = Header(val, settings.DEFAULT_CHARSET) 35 35 MIMEText.__setitem__(self, name, val) 36 36 37 def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None ):37 def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, additional_headers_dict={}): 38 38 """ 39 39 Easy wrapper for sending a single message to a recipient list. All members 40 40 of the recipient list will see the other recipients in the 'To' field. … … 46 46 auth_user = settings.EMAIL_HOST_USER 47 47 if auth_password is None: 48 48 auth_password = settings.EMAIL_HOST_PASSWORD 49 return send_mass_mail([[subject, message, from_email, recipient_list ]], fail_silently, auth_user, auth_password)49 return send_mass_mail([[subject, message, from_email, recipient_list, additional_headers_dict]], fail_silently, auth_user, auth_password) 50 50 51 51 def send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None): 52 52 """ … … 71 71 return 72 72 raise 73 73 num_sent = 0 74 for subject, message, from_email, recipient_list in datatuple:74 for subject, message, from_email, recipient_list, additional_headers_dict in datatuple: 75 75 if not recipient_list: 76 76 continue 77 77 from_email = from_email or settings.DEFAULT_FROM_EMAIL … … 85 85 except AttributeError: # Python 2.3 doesn't have random.getrandbits(). 86 86 random_bits = ''.join([random.choice('1234567890') for i in range(19)]) 87 87 msg['Message-ID'] = "<%d.%s@%s>" % (time.time(), random_bits, DNS_NAME) 88 core_headers = ['Subject', 'From', 'To', 'Date', 'Message-ID'] 89 for header in additional_headers_dict: 90 if header not in core_headers: 91 msg[header] = additional_headers_dict[header] 88 92 try: 89 93 server.sendmail(from_email, recipient_list, msg.as_string()) 90 94 num_sent += 1