1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #19325 - Made email backend of AdminEmailHandler configurable

This commit is contained in:
Hannes Struss
2012-11-19 18:57:40 +01:00
parent 1f1f60d12f
commit f9891f2087
5 changed files with 69 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ import traceback
from django.conf import settings
from django.core import mail
from django.core.mail import get_connection
from django.views.debug import ExceptionReporter, get_exception_reporter_filter
@@ -76,9 +77,10 @@ class AdminEmailHandler(logging.Handler):
request data will be provided in the email report.
"""
def __init__(self, include_html=False):
def __init__(self, include_html=False, email_backend=None):
logging.Handler.__init__(self)
self.include_html = include_html
self.email_backend = email_backend
def emit(self, record):
try:
@@ -110,7 +112,12 @@ class AdminEmailHandler(logging.Handler):
message = "%s\n\n%s" % (stack_trace, request_repr)
reporter = ExceptionReporter(request, is_email=True, *exc_info)
html_message = self.include_html and reporter.get_traceback_html() or None
mail.mail_admins(subject, message, fail_silently=True, html_message=html_message)
mail.mail_admins(subject, message, fail_silently=True,
html_message=html_message,
connection=self.connection())
def connection(self):
return get_connection(backend=self.email_backend)
def format_subject(self, subject):
"""