Ticket #3307: only_suppress_recipients.diff

File only_suppress_recipients.diff, 2.8 KB (added by mssnlayam@…, 18 years ago)

Patch with only suppress_recipients

  • django/core/mail.py

     
    2929    """
    3030    return send_mass_mail([[subject, message, from_email, recipient_list]], fail_silently, auth_user, auth_password)
    3131
    32 def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD):
     32def send_mass_mail(datatuple, fail_silently=False, auth_user=settings.EMAIL_HOST_USER, auth_password=settings.EMAIL_HOST_PASSWORD, suppress_recipients=False):
    3333    """
    3434    Given a datatuple of (subject, message, from_email, recipient_list), sends
    3535    each message to each recipient list. Returns the number of e-mails sent.
    3636
    3737    If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
    3838    If auth_user and auth_password are set, they're used to log in.
     39    If suppress_recipients is True, the first address in the recipients list
     40    will be inserted into the 'To:' field and all other addresses will be
     41    inserted into the 'Bcc:' field.
    3942    """
    4043    try:
    4144        server = smtplib.SMTP(settings.EMAIL_HOST, settings.EMAIL_PORT)
     
    5356        msg = SafeMIMEText(message, 'plain', settings.DEFAULT_CHARSET)
    5457        msg['Subject'] = subject
    5558        msg['From'] = from_email
    56         msg['To'] = ', '.join(recipient_list)
     59        if suppress_recipients:
     60            msg['To'] = recipient_list[0]
     61            if len(recipient_list) > 1:
     62                msg['Bcc'] = ', '.join(recipient_list[1:])
     63        else:
     64            msg['To'] = ', '.join(recipient_list)
    5765        msg['Date'] = rfc822.formatdate()
    5866        try:
    5967            random_bits = str(random.getrandbits(64))
  • docs/email.txt

     
    6565Here's the definition::
    6666
    6767    send_mass_mail(datatuple, fail_silently=False,
    68         auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD):
     68        auth_user=EMAIL_HOST_USER, auth_password=EMAIL_HOST_PASSWORD,
     69        suppress_recipients=False):
    6970
    7071``datatuple`` is a tuple in which each element is in this format::
    7172
     
    7677
    7778Each separate element of ``datatuple`` results in a separate e-mail message.
    7879As in ``send_mail()``, recipients in the same ``recipient_list`` will all see
    79 the other addresses in the e-mail messages's "To:" field.
     80the other addresses in the e-mail messages's "To:" field. To suppress all but
     81a single address (useful for newsletters or mailing lists), use
     82``suppress_recipients=True``; this will use the first address in the "To:"
     83field, and place all other addresses in the "Bcc:" field.
    8084
    8185send_mass_mail() vs. send_mail()
    8286--------------------------------
Back to Top