[Fixed]-Django Mailgun BCC

1👍

As said by solarissmoke above, django-mailgun doesn’t support BCC. At least by default. If you go into the source code it is easy enough to add bcc support. Within the django_mailgun.py file change from:

    recipients = [sanitize_address(addr, email_message.encoding)
                  for addr in email_message.recipients()]

    try:

        post_data = []
        post_data.append(('to', (",".join(recipients)),))

to:

    to_recip = [sanitize_address(addr, email_message.encoding)
                  for addr in email_message.to]

    bcc_recip = [sanitize_address(addr, email_message.encoding)
                  for addr in email_message.bcc]

    try:

        post_data = []
        post_data.append(('to', (",".join(to_recip)),))
        post_data.append(('bcc', (",".join(bcc_recip)),))

and voila, bcc support. You can also make changes similar to above to add cc support. It turned out they were just straight reading recipients which caused bcc to be dropped and just added them directly in the to list. Hope this helped out anyone else who may have encountered a similar issue.

Leave a comment