Ticket #9383: mail_admins.diff
File mail_admins.diff, 4.4 KB (added by , 16 years ago) |
---|
-
django/core/handlers/base.py
148 148 return debug.technical_500_response(request, *exc_info) 149 149 150 150 # When DEBUG is False, send an error message to the admins. 151 subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) 152 try: 153 request_repr = repr(request) 154 except: 155 request_repr = "Request repr() unavailable" 156 message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) 157 mail_admins(subject, message, fail_silently=True) 151 if settings.ADMINS: 152 subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path) 153 try: 154 request_repr = repr(request) 155 except: 156 request_repr = "Request repr() unavailable" 157 message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr) 158 mail_admins(subject, message, fail_silently=True) 159 158 160 # Return an HttpResponse that displays a friendly error message. 159 161 callback, param_dict = resolver.resolve500() 160 162 return callback(request, **param_dict) -
django/core/mail.py
366 366 367 367 def mail_admins(subject, message, fail_silently=False): 368 368 """Sends a message to the admins, as defined by the ADMINS setting.""" 369 EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, 369 if settings.ADMINS: 370 EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, 370 371 settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS] 371 372 ).send(fail_silently=fail_silently) 372 373 373 374 def mail_managers(subject, message, fail_silently=False): 374 375 """Sends a message to the managers, as defined by the MANAGERS setting.""" 375 EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, 376 if settings.MANAGERS: 377 EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, 376 378 settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS] 377 379 ).send(fail_silently=fail_silently) -
tests/regressiontests/mail/tests.py
2 2 r""" 3 3 # Tests for the django.core.mail. 4 4 5 >>> from django.core.mail import EmailMessage 5 >>> from django.core.mail import EmailMessage, mail_admins, mail_managers 6 6 >>> from django.utils.translation import ugettext_lazy 7 7 8 8 # Test normal ascii character case: … … 60 60 >>> email.message().as_string() 61 61 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nContent-Transfer-Encoding: quoted-printable\nSubject: subject\nFrom: from@example.com\nTo: to@example.com\ndate: Fri, 09 Nov 2001 01:08:47 -0000\nMessage-ID: foo\n\ncontent' 62 62 63 # Test that mail_admins/mail_managers doesn't connect to the mail server if there are no recipients (#9383) 64 65 >>> from django.core import mail 66 >>> from django.conf import settings 67 >>> old_admins = settings.ADMINS 68 >>> old_managers = settings.MANAGERS 69 >>> settings.ADMINS = [] 70 >>> settings.MANAGERS = [] 71 >>> mail.outbox = [] 72 >>> mail_admins('hi','there') 73 >>> len(mail.outbox) 74 0 75 >>> mail.outbox = [] 76 >>> mail_managers('hi','there') 77 >>> len(mail.outbox) 78 0 79 >>> settings.ADMINS = settings.MANAGERS = [('nobody','nobody@example.com')] 80 >>> mail.outbox = [] 81 >>> mail_admins('hi','there') 82 >>> len(mail.outbox) 83 1 84 >>> mail.outbox = [] 85 >>> mail_managers('hi','there') 86 >>> len(mail.outbox) 87 1 88 >>> settings.ADMINS = old_admins 89 >>> settings.MANAGERS = old_managers 90 63 91 """ -
docs/topics/email.txt
106 106 The "From:" header of the e-mail will be the value of the 107 107 :setting:`SERVER_EMAIL` setting. 108 108 109 If :setting:`ADMINS` is empty, this function does nothing. 110 109 111 This method exists for convenience and readability. 110 112 111 113 mail_managers() function