mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #9383 -- Don't open a network connection for sending email if there's
nothing to send. Saves a bit of time when, for example, processing 500-error emails with no ADMINs configured. Based on a patch from Jesse Young. git-svn-id: http://code.djangoproject.com/svn/django/trunk@9248 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -268,6 +268,10 @@ class EmailMessage(object):
|
||||
|
||||
def send(self, fail_silently=False):
|
||||
"""Sends the email message."""
|
||||
if not self.recipients():
|
||||
# Don't bother creating the network connection if there's nobody to
|
||||
# send to.
|
||||
return 0
|
||||
return self.get_connection(fail_silently).send_messages([self])
|
||||
|
||||
def attach(self, filename=None, content=None, mimetype=None):
|
||||
@@ -366,12 +370,16 @@ def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
|
||||
|
||||
def mail_admins(subject, message, fail_silently=False):
|
||||
"""Sends a message to the admins, as defined by the ADMINS setting."""
|
||||
if not settings.ADMINS:
|
||||
return
|
||||
EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
|
||||
settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS]
|
||||
).send(fail_silently=fail_silently)
|
||||
|
||||
def mail_managers(subject, message, fail_silently=False):
|
||||
"""Sends a message to the managers, as defined by the MANAGERS setting."""
|
||||
if not settings.MANAGERS:
|
||||
return
|
||||
EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
|
||||
settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS]
|
||||
).send(fail_silently=fail_silently)
|
||||
|
||||
Reference in New Issue
Block a user