0

I am really novice with Django, and I am having troubles in configuring my app to send me emails with the bug reports.

I already set on the settings file the required variables as I saw on the Django documentation, like this:

DEBUG = False
...
ADMINS = [('myname', 'myemail@server')]   # For server errors
MANAGERS = [('myname', 'myemail@server')] # For missing pages errors

I provoked a error for testing, but nothing happened, no email. What should I do?

This is the code of the settings file (without sensitive data, of course):

"""
Django settings for genform project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

SECRET_KEY = '****************************************'

DEBUG = False

ALLOWED_HOSTS = []

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'widget_tweaks',
    'generador',
    'menu',
    'parametros_transformados',
    'seguridad',
    'tablas_de_no_parametros',
    'reportes',
    'logger',
    'parametros',
    'django_openid_auth'
     )

SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

)

AUTHENTICATION_BACKENDS = (
    'django_openid_auth.auth.OpenIDBackend',
    'django.contrib.auth.backends.ModelBackend',
)

TEMPLATES = [
    {
        'BACKEND':'django.template.backends.django.DjangoTemplates',
        'DIRS':[os.path.join(os.path.dirname(__file__), '../templates')],
        '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',
            ],
        },
    },
]

OPENID_UPDATE_DETAILS_FROM_SREG = True

ROOT_URLCONF = 'genform.urls'

WSGI_APPLICATION = 'genform.wsgi.application'

DATABASES = {
'default': {
     'ENGINE': 'django.db.backends.postgresql_psycopg2',
     'NAME': '*****',
     'USER': '******',
     'PASSWORD': '******',
     'HOST': '***********',
     'PORT': '***',
     }
}

STATICFILES_DIRS = (
    #os.path.dirname(__file__)+"static",
    # Put strings here, like "/home/html/site_media" or "C:/www/django/site_media".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(os.path.dirname(__file__), '../static'),
)

AUTH_PROFILE_MODULE = 'seguridad.c_perfil_usuario'

LOGIN_REDIRECT_URL = '/index'

OPENID_SSO_SERVER_URL = '***********'

OPENID_CREATE_USERS = True

LANGUAGE_CODE = 'es-es'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_URL = '/static/'

ADMINS = [('MyName', 'myemail@server')]

MANAGERS = [('MyName', 'myemail@server')]
Luis
  • 3
  • 4

2 Answers2

1

What's your LOGGING configuration? I use the following in my production environment:

ADMINS = [
    ('Admin1', 'admin1@mail.com'),
    ('Admin2', 'admin2@mail.com')
]

MANAGERS = ADMINS

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'  # for testing
EMAIL_HOST = 'relay.server.com'

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s '
                      '%(process)d %(thread)d %(message)s'
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false', ],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'verbose',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins', ],
            'level': 'ERROR',
            'propagate': True
        },
        'django.security.DisallowedHost': {
            'level': 'ERROR',
            'handlers': ['console', 'mail_admins', ],
            'propagate': True
        }
    }
}

Make sure you have a valid EMAIL_BACKEND defined. You can use a service like mailgun or even gmail if you don't have a own SMTP server (EMAIL_HOST).

Yannic Hamann
  • 4,655
  • 32
  • 50
0

Thoese settings look correct, but there are other things that may be holding you up.

  1. Email info in settings.py may not be configured

  2. You have overwritten the default log settings in settings.py and are not writing errors to the email log.

If one or both of these are not setup correctly, then you won't get the emails.

To fix 1 you can look at this answer: https://stackoverflow.com/a/4642194/4788717

To fix 2, you can check out the docs: https://docs.djangoproject.com/en/dev/topics/logging/ and make sure you have either the default or mail admins case:

LOGGING = {
...
'mail_admins': {
        'level': 'ERROR',
        'class': 'django.utils.log.AdminEmailHandler',
        'filters': ['special']
...
}
ryati
  • 360
  • 3
  • 13