Django not sending emails to admins

后端 未结 20 1111
梦如初夏
梦如初夏 2020-12-08 08:54

According to the documentation, if DEBUG is set to False and something is provided under the ADMINS setting, Django will send an email

相关标签:
20条回答
  • 2020-12-08 09:39

    I had the same situation. I created a new project and app and it worked, so I knew it was my code. I tracked it down to the LOGGING dictionary in settings.py. I had made some changes a few weeks back for logging with Sentry, but for some reason the error just started today. I changed back to the original and got it working:

    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,
            },
        }
    }
    

    Then, I made some changes slowly and got it working with Sentry and emailing the ADMINS as well.

    Additionally, the LOGGING configuration gets merged with DEFAULT_LOGGING by default, so it's useful to have a look at the source code of django.utils.log.DEFAULT_LOGGING to understand what else may have an effect on your particular situation.

    0 讨论(0)
  • 2020-12-08 09:39

    Although it's been a while, here's my response, so that other people can benefit in the future.

    In my case, what was preventing emails to be sent to the ADMINS list, when an error occured, was an application specific setting. I was using django-piston, which provides the setting attributes PISTON_EMAIL_ERRORS and PISTON_DISPLAY_ERRORS. Setting these accordingly, enabled the application server to notify my by mail, whenever piston would crash.

    0 讨论(0)
  • 2020-12-08 09:39

    The below info is given in https://docs.djangoproject.com/en/2.1/howto/error-reporting/#email-reports

    EMAIL_HOST = "email host"
    
    EMAIL_HOST_USER = "Email username"
    
    EMAIL_HOST_PASSWORD = "Email Password"
    
    DEBUG = False
    
    ADMINS = (
        ("Your Name", "your_email@company.com")
    )
    

    In order to send email, Django requires a few settings telling it how to connect to your mail server. At the very least, you’ll need to specify EMAIL_HOST and possibly EMAIL_HOST_USER and EMAIL_HOST_PASSWORD, though other settings may be also required depending on your mail server’s configuration. Consult the Django settings documentation for a full list of email-related settings.

    0 讨论(0)
  • 2020-12-08 09:40

    Just had the same issue after upgraded to Django 2.1 from Django 1.11. Apparently the ADMINS sections in settings.py has a change. It takes a list of tuples now, rather than the old tuple of tuples. This fixed for me.

    ##### old #####
    ADMINS = (
        ("Your Name", "your_email@company.com")
    )
    
    ##### new #####
    ADMINS = [
        ("Your Name", "your_email@company.com")
    ]
    

    Re: https://docs.djangoproject.com/en/2.1/ref/settings/#admins

    0 讨论(0)
  • 2020-12-08 09:40

    In my case, it's the include_html in mail_admins.

    When I set include_html to True,the email server reject to send my email because it think that my emails are spam.

    Everything works just fine when I set include_html to False.

    0 讨论(0)
  • 2020-12-08 09:41

    ... and then there's the facepalm error, when you've used this in development to prevent emails from going out, and then accidentally copy the setting to production:

    # Print emails to console
    EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
    

    (of course you don't see them being printed to console when using a wsgi server). Removing the setting from production fixed this for me.

    0 讨论(0)
提交回复
热议问题