Django emailing on errors

2020-04-12 04:51发布

问题:

I have been struggling to get the emailing to work in Django for logging as well as for 500 and 404 errors and for the life of me I cant get it to work. I have DEBUG=False and all the other settings. I have the below for the email settings:

EMAIL_HOST = 'host'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'username'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_SUBJECT_PREFIX = 'something'
EMAIL_USE_TLS = True
SERVER_EMAIL='blah@blah.com'

I'm using Amazon SES for the above settings. I also have the following:

SEND_BROKEN_LINK_EMAILS=True
ADMINS = (
    ('name', 'email'),
)
MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
)

Is there anything else I'm missing?? Any help is appreciated.

回答1:

Yep, it's not ADMINS = () that receives SEND_BROKEN_LINK_EMAILS, it's MANAGERS = ()

https://docs.djangoproject.com/en/dev/ref/settings/#managers

https://docs.djangoproject.com/en/dev/howto/error-reporting/#errors

Add this right under ADMINS and it should work:

MANAGERS = ADMINS

You may also want to specify EMAIL_BACKEND in settings, e.g. assuming SMTP:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

https://docs.djangoproject.com/en/dev/ref/settings/#email-backend



标签: django email