Code

Ticket #10863: 10863.diff

File 10863.diff, 2.5 KB (added by boxed, 5 years ago)
Line 
1Index: /Users/boxed/django/django/core/handlers/base.py
2===================================================================
3--- /Users/boxed/django/django/core/handlers/base.py    (revision 10581)
4+++ /Users/boxed/django/django/core/handlers/base.py    (working copy)
5@@ -154,13 +154,17 @@
6             return debug.technical_500_response(request, *exc_info)
7 
8         # When DEBUG is False, send an error message to the admins.
9+        from django.views.debug import ExceptionReporter
10+        reporter = ExceptionReporter(request, *exc_info)
11+        html = reporter.get_traceback_html()
12+
13         subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
14         try:
15             request_repr = repr(request)
16         except:
17             request_repr = "Request repr() unavailable"
18         message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
19-        mail_admins(subject, message, fail_silently=True)
20+        mail_admins(subject, message, fail_silently=True, html_message=html)
21         # Return an HttpResponse that displays a friendly error message.
22         callback, param_dict = resolver.resolve500()
23         return callback(request, **param_dict)
24Index: /Users/boxed/django/django/core/mail.py
25===================================================================
26--- /Users/boxed/django/django/core/mail.py     (revision 10581)
27+++ /Users/boxed/django/django/core/mail.py     (working copy)
28@@ -368,13 +368,15 @@
29                 for subject, message, sender, recipient in datatuple]
30     return connection.send_messages(messages)
31 
32-def mail_admins(subject, message, fail_silently=False):
33+def mail_admins(subject, message, fail_silently=False, html_message=None):
34     """Sends a message to the admins, as defined by the ADMINS setting."""
35     if not settings.ADMINS:
36         return
37-    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
38-                 settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS]
39-                 ).send(fail_silently=fail_silently)
40+    from django.core.mail import EmailMultiAlternatives
41+    msg = EmailMultiAlternatives(settings.EMAIL_SUBJECT_PREFIX + subject, message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS])
42+    if html_message:
43+        msg.attach_alternative(html_message, "text/html")
44+    msg.send(fail_silently=fail_silently)
45 
46 def mail_managers(subject, message, fail_silently=False):
47     """Sends a message to the managers, as defined by the MANAGERS setting."""