Mirac7
Mirac7

Reputation: 1646

Sending error triggered emails to selected admins only

When a 500 error occurs on the server, django automatically emails all admins. That is a great feature, but what if some admins want to opt out? Is is possible for admins to choose whether or not they want django to email them when error occurs? Server is logging all errors anyway and data is available for revision to all admins when they log in to the site.

Upvotes: 1

Views: 155

Answers (1)

Simeon Visser
Simeon Visser

Reputation: 122436

In Django 1.8 there will be the ability to override who receives an email when an error occurs. It's also possible in earlier Django versions but the code will be uglier.

Django sends the error emails using Python's logging framework and this can be customised (see documentation). In particular the handler has the following method:

send_mail(subject, message, *args, **kwargs): Sends emails to admin users. To customize this behavior, you can subclass the AdminEmailHandler class and override this method.

This calls django.core.mail.mail_admins which by default sends an email to all entries in settings.ADMINS. You'll instead need to use django.core.mail.send_mail to customise who you wish to send an email (i.e., take settings.ADMINS, apply the filtering and call send_maiL yourself with the recipient list as desired).

Upvotes: 1

Related Questions