'Why are the error reporting emails not being sent (Django)?
Python version: 3.6.3 Django version: 3.0.8
I am trying to use enable Django's error reporting via email, but nothing seems to happen when I encounter a 500 error. Here is a copy of my settings file with some comments and sensitive information removed:
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '' # The actual value has been omitted
DEBUG = False
ADMINS = [('', '')] # Omitted. The same email address is used for EMAIL_HOST_USER and SERVER_EMAIL
MANAGERS = ADMINS
ALLOWED_HOSTS = ['.localhost', '127.0.0.1', '[::1]']
# ALLOWED_HOSTS = []
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST_USER = ''
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_PSSWORD = '' # Omitted
SERVER_EMAIL = ''
# The logging settings are intentionally commented out. Whether or not they were there seemed to make no difference. Nor did any of the suggested changes I tried.
"""
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
"""
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'crispy_forms',
'main.apps.MainConfig',
'register.apps.RegisterConfig'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'
AUTH_USER_MODEL = 'register.CustomUser'
So far, I have tried all the answers from the following: Django not sending emails to admins Django not sending error emails - how can I debug? Django doesn't email reporting an internal server error (HTTP status code 500) Receive django error debug report by email :
None of them seem to have done anything except 2 answers in the last link which caused ValueError: The ADMINS setting must be a list of 2-tuples
. I do not think the issue is with the email address I am using since I have been using it to send/receive emails through other Python scripts unrelated to Django. I think I am just failing to integrate it properly.
Any advice would be greatly appreciated.
Solution 1:[1]
I have the same problem - Django server error reporting isn't working. Below are my settings.
DEBUG = False
ADMINS = [('Rama', '[email protected]'), ('Bheema', '[email protected]'),]
EMAIL_USE_TLS = True
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
SERVER_EMAIL = '[email protected]'
EMAIL_HOST_USER = "[email protected]"
EMAIL_HOST_PASSWORD = "<app_password>"
Appreciate inputs from anyone who got this working.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Harsha N Hegde |