Skip to content
Snippets Groups Projects
Commit 2906f1d7 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

Change mechanism for sending emails

Instead of looping over EmailMessage.send() calls, we now get the
email backend and send a list of messages. Note that the backend
sends the messages individually still but this cuts out some of the
overhead.
parent d7ab65db
No related branches found
No related tags found
No related merge requests found
......@@ -603,7 +603,7 @@ LOGGING = {
'propagate': True,
'level': LOG_LEVEL,
},
'django.request': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': False,
......
......@@ -3,7 +3,7 @@ import logging
import textwrap
from django.conf import settings
from django.core.mail import EmailMessage
from django.core.mail import EmailMessage, get_connection
from django.urls import reverse
from core.time_utils import gpsToUtc
......@@ -143,10 +143,13 @@ def issue_email_alerts(event_or_superevent, alert_type, recipients,
logger.debug("Sending email to {recips}".format(
recips=", ".join([r.email for r in recipients])))
# Send mail individually so all emails are not rejected due to a single
# address being blacklisted
# Construct email messages
messages = []
for recip in recipients:
# Send email
email = EmailMessage(subject=subject, body=email_body,
from_email=settings.ALERT_EMAIL_FROM, to=[recip.email])
email.send()
messages.append(email)
# Send email messages
backend = get_connection()
backend.send_messages(messages)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment