Default BCC recipients for mail

This commit is contained in:
Kumi 2021-05-30 07:44:01 +02:00
parent cde75f0f6c
commit 2c95e31e56
2 changed files with 10 additions and 1 deletions

View file

@ -23,6 +23,10 @@ EMAIL_HOST_PASSWORD = "mail_password"
EMAIL_USE_TLS = False
EMAIL_USE_SSL = True
# Email address to send outgoing mail from by default
DEFAULT_FROM_EMAIL = "noreply@example.com"
# Email addresses of system administrators and managers
ADMINS = [
@ -33,6 +37,10 @@ MANAGERS = ADMINS + [
('Demo Manager', 'manager@example.com'),
]
# Default addresses to BCC messages to
DEFAULT_BCC_EMAILS = []
# S3 Bucket Configuration (add options as documented at https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html)
ENABLE_S3_STORAGE = False

View file

@ -2,6 +2,7 @@ from django.views.generic.base import ContextMixin
from django.template.loader import render_to_string
from django.template.exceptions import TemplateDoesNotExist
from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from html.parser import HTMLParser
@ -48,7 +49,7 @@ class MailView(ContextMixin):
def send(self, subject, recipient, context={}, attachments=[], sender=None, cc=[], bcc=[], text_from_html=False):
text = self.render_to_text(text_from_html, **context)
email = EmailMultiAlternatives(subject, text, sender, [recipient], cc=cc, bcc=bcc, attachments=attachments)
email = EmailMultiAlternatives(subject, text, sender, [recipient], cc=cc, bcc=bcc + DEFAULT_BCC_EMAILS attachments=attachments)
if html := self.render_to_html(**context):
email.attach_alternative(html, "text/html")
email.send()