mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-14 23:02:19 +00:00
Send individual mails, to avoid showing the whole to list, BCC and spamholing from Google
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.mail import EmailMultiAlternatives
|
from django.core.mail import EmailMultiAlternatives, get_connection
|
||||||
from django.template.loader import get_template
|
from django.template.loader import get_template
|
||||||
from django.template import Context
|
from django.template import Context
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
@@ -9,7 +9,13 @@ def send_group_email(request, to_email, subject, email_text_template, email_html
|
|||||||
|
|
||||||
# Mail the admins to inform them of a new request
|
# Mail the admins to inform them of a new request
|
||||||
ctx = Context({'request': request, 'domain': Site.objects.get_current().domain})
|
ctx = Context({'request': request, 'domain': Site.objects.get_current().domain})
|
||||||
msg = EmailMultiAlternatives(subject, get_template(email_text_template).render(ctx), getattr(settings, 'DEFAULT_FROM_EMAIL', 'auth@pleaseignore.com'), to_email)
|
|
||||||
msg.attach_alternative(get_template(email_html_template).render(ctx), 'text/html')
|
messages = [generate_mail(ctx, email_text_template, email_html_template, to, subject) for to in to_email]
|
||||||
msg.send(fail_silently=True)
|
connection = get_connection(fail_silently=True)
|
||||||
|
connection.send_messages(messages)
|
||||||
|
|
||||||
|
def generate_mail(context, email_text_template, email_html_template, to, subject):
|
||||||
|
msg = EmailMultiAlternatives(subject, get_template(email_text_template).render(context), getattr(settings, 'DEFAULT_FROM_EMAIL', 'auth@pleaseignore.com'), [to])
|
||||||
|
msg.attach_alternative(get_template(email_html_template).render(context), 'text/html')
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user