Ticket #3985: mail-additional_headers.2.diff

File mail-additional_headers.2.diff, 2.1 KB (added by meren@…, 18 years ago)

less messy..

  • core/mail.py

     
    3434            val = Header(val, settings.DEFAULT_CHARSET)
    3535        MIMEText.__setitem__(self, name, val)
    3636
    37 def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None):
     37def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, additional_headers_dict={}):
    3838    """
    3939    Easy wrapper for sending a single message to a recipient list. All members
    4040    of the recipient list will see the other recipients in the 'To' field.
     
    4646        auth_user = settings.EMAIL_HOST_USER
    4747    if auth_password is None:
    4848        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)
    5050
    5151def send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None):
    5252    """
     
    7171            return
    7272        raise
    7373    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:
    7575        if not recipient_list:
    7676            continue
    7777        from_email = from_email or settings.DEFAULT_FROM_EMAIL
     
    8585        except AttributeError: # Python 2.3 doesn't have random.getrandbits().
    8686            random_bits = ''.join([random.choice('1234567890') for i in range(19)])
    8787        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]
    8892        try:
    8993            server.sendmail(from_email, recipient_list, msg.as_string())
    9094            num_sent += 1
Back to Top