diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
index b03c2fd..10a2ac2 100644
a
|
b
|
class BaseHandler(object):
|
165 | 165 | return debug.technical_500_response(request, *exc_info) |
166 | 166 | |
167 | 167 | # When DEBUG is False, send an error message to the admins. |
| 168 | from django.views.debug import ExceptionReporter |
| 169 | reporter = ExceptionReporter(request, *exc_info) |
| 170 | html_message = reporter.get_traceback_html() |
| 171 | |
168 | 172 | subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) |
169 | 173 | try: |
170 | 174 | request_repr = repr(request) |
171 | 175 | except: |
172 | 176 | request_repr = "Request repr() unavailable" |
173 | 177 | message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) |
174 | | mail_admins(subject, message, fail_silently=True) |
| 178 | mail_admins(subject, message, fail_silently=True, |
| 179 | html_message=html_message) |
175 | 180 | # If Http500 handler is not installed, re-raise last exception |
176 | 181 | if resolver.urlconf_module is None: |
177 | 182 | raise exc_info[1], None, exc_info[2] |
diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py
index f9d1210..7c26cc8 100644
a
|
b
|
def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
|
83 | 83 | return connection.send_messages(messages) |
84 | 84 | |
85 | 85 | |
86 | | def mail_admins(subject, message, fail_silently=False, connection=None): |
| 86 | def mail_admins(subject, message, html_message=None, |
| 87 | fail_silently=False, connection=None): |
87 | 88 | """Sends a message to the admins, as defined by the ADMINS setting.""" |
88 | 89 | if not settings.ADMINS: |
89 | 90 | return |
90 | | EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, |
91 | | settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], |
92 | | connection=connection).send(fail_silently=fail_silently) |
93 | | |
94 | | |
95 | | def mail_managers(subject, message, fail_silently=False, connection=None): |
| 91 | mail = EmailMultiAlternatives(settings.EMAIL_SUBJECT_PREFIX + subject, |
| 92 | message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], |
| 93 | connection=connection) |
| 94 | if html_message: |
| 95 | mail.attach_alternative(html_message, 'text/html') |
| 96 | mail.send(fail_silently=fail_silently) |
| 97 | |
| 98 | def mail_managers(subject, message, html_message=None, |
| 99 | fail_silently=False, connection=None): |
96 | 100 | """Sends a message to the managers, as defined by the MANAGERS setting.""" |
97 | 101 | if not settings.MANAGERS: |
98 | 102 | return |
99 | | EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, |
100 | | settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], |
101 | | connection=connection).send(fail_silently=fail_silently) |
102 | | |
| 103 | mail = EmailMultiAlternatives(settings.EMAIL_SUBJECT_PREFIX + subject, |
| 104 | message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], |
| 105 | connection=connection) |
| 106 | if html_message: |
| 107 | mail.attach_alternative(html_message, 'text/html') |
| 108 | mail.send(fail_silently=fail_silently) |
103 | 109 | |
104 | 110 | class SMTPConnection(_SMTPConnection): |
105 | 111 | def __init__(self, *args, **kwds): |
diff --git a/docs/topics/email.txt b/docs/topics/email.txt
index 31092b0..56190fe 100644
a
|
b
|
mail_admins()
|
113 | 113 | ``django.core.mail.mail_admins()`` is a shortcut for sending an e-mail to the |
114 | 114 | site admins, as defined in the :setting:`ADMINS` setting. Here's the definition: |
115 | 115 | |
116 | | .. function:: mail_admins(subject, message, fail_silently=False, connection=None) |
| 116 | .. function:: mail_admins(subject, message, html_message=None, fail_silently=False, connection=None) |
117 | 117 | |
118 | 118 | ``mail_admins()`` prefixes the subject with the value of the |
119 | 119 | :setting:`EMAIL_SUBJECT_PREFIX` setting, which is ``"[Django] "`` by default. |
… |
… |
The "From:" header of the e-mail will be the value of the
|
123 | 123 | |
124 | 124 | This method exists for convenience and readability. |
125 | 125 | |
| 126 | .. versionchanged:: 1.3 |
| 127 | |
| 128 | If ``html_message`` is provided, the resulting e-mail will be a |
| 129 | multipart/alternative e-mail with ``message`` as the "text/plain" |
| 130 | content type and ``html_message`` as the "text/html" content type. |
| 131 | |
126 | 132 | mail_managers() function |
127 | 133 | ======================== |
128 | 134 | |
… |
… |
mail_managers() function
|
130 | 136 | sends an e-mail to the site managers, as defined in the :setting:`MANAGERS` |
131 | 137 | setting. Here's the definition: |
132 | 138 | |
133 | | .. function:: mail_managers(subject, message, fail_silently=False, connection=None) |
| 139 | .. function:: mail_managers(subject, message, html_message=None, fail_silently=False, connection=None) |
134 | 140 | |
135 | 141 | Examples |
136 | 142 | ======== |
diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
index 84be585..dc7bc41 100644
a
|
b
|
Message-ID: ...
|
414 | 414 | Content |
415 | 415 | ------------------------------------------------------------------------------- |
416 | 416 | |
| 417 | # Test html_message argument to mail_admins and mail_managers |
| 418 | >>> mail_managers('Subject', 'Content', connection=connection, html_message='HTML Content') |
| 419 | Content-Type: multipart/alternative; |
| 420 | ...boundary=... |
| 421 | MIME-Version: 1.0 |
| 422 | Subject: [Django] Subject |
| 423 | From: root@localhost |
| 424 | To: nobody@example.com |
| 425 | Date: ... |
| 426 | Message-ID: ... |
| 427 | |
| 428 | --===============... |
| 429 | Content-Type: text/plain; charset="utf-8" |
| 430 | MIME-Version: 1.0 |
| 431 | Content-Transfer-Encoding: quoted-printable |
| 432 | |
| 433 | Content |
| 434 | --===============... |
| 435 | Content-Type: text/html; charset="utf-8" |
| 436 | MIME-Version: 1.0 |
| 437 | Content-Transfer-Encoding: quoted-printable |
| 438 | |
| 439 | HTML Content |
| 440 | --===============... |
| 441 | ------------------------------------------------------------------------------- |
| 442 | |
| 443 | >>> mail_admins('Subject', 'Content', connection=connection, html_message='HTML Content') |
| 444 | Content-Type: multipart/alternative; |
| 445 | ...boundary=... |
| 446 | MIME-Version: 1.0 |
| 447 | Subject: [Django] Subject |
| 448 | From: root@localhost |
| 449 | To: nobody@example.com |
| 450 | Date: ... |
| 451 | Message-ID: ... |
| 452 | |
| 453 | --===============... |
| 454 | Content-Type: text/plain; charset="utf-8" |
| 455 | MIME-Version: 1.0 |
| 456 | Content-Transfer-Encoding: quoted-printable |
| 457 | |
| 458 | Content |
| 459 | --===============... |
| 460 | Content-Type: text/html; charset="utf-8" |
| 461 | MIME-Version: 1.0 |
| 462 | Content-Transfer-Encoding: quoted-printable |
| 463 | |
| 464 | HTML Content |
| 465 | --===============... |
| 466 | ------------------------------------------------------------------------------- |
| 467 | |
417 | 468 | >>> settings.ADMINS = old_admins |
418 | 469 | >>> settings.MANAGERS = old_managers |
419 | 470 | |