#28598: BCC addresses are ignored in the console and file email backends
-------------------------------------+-------------------------------------
Reporter: zngr | Owner: Josh
Type: | Schneier
Cleanup/optimization | Status: assigned
Component: Core (Mail) | Version: 1.11
Severity: Normal | Resolution:
Keywords: mail, bcc | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Michael):
Mariusz Felisiak
Hi Mariusz, is what I came up with, do you the solution is good enough for
the Django Core? If it is a will create a patch out of it
{{{
import re
from io import StringIO
from django.core.mail.backends.console import EmailBackend
class WithBccEmailBackend(EmailBackend):
"""Email backend that writes messages to console instead of sending
them, by defaul
the Django Console back end does not print the Bcc fields, with just
predixes
the original output with the Bcc field.
"""
def write_message(self, message):
if message.bcc:
self.stream_backup = self.stream
self.stream = StringIO()
super().write_message(message)
content = self.stream.getvalue()
bcc = f"Bcc: {', '.join(message.bcc)}\n"
new_content = re.sub(r'(Reply-To: |Date: )', bcc + r'\g<1>',
content, 1)
self.stream = self.stream_backup
self.stream.write(new_content)
else:
super().write_message(message)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28598#comment:19>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070182350d6581-61b35e90-9c18-454a-a66a-3b501fa9127a-000000%40eu-central-1.amazonses.com.