Django not sending emails to admins

后端 未结 20 1109
梦如初夏
梦如初夏 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:33

    Another thing worth noting here is that settings handler500 might bypass the mechanism that sends errors on a 500 if the response from the view doesn't have a status code of 500. If you have a handler500 set, then in that view respond with something like this.

    t = loader.get_template('500.html')
    response = HttpResponseServerError(
        t.render(RequestContext(request, {'custom_context_var': 
            'IT BROKE OMG FIRE EVERYONE'})))
    response.status_code = 500
    return response
    
    0 讨论(0)
  • 2020-12-08 09:34

    Try this

    # ./manage shell
    >>> from django.core.mail import send_mail
    >>> send_mail('Subject here', 'Here is the message.', 'from@example.com',['to@example.com'], fail_silently=False)
    

    With a to@example.com that you actually get email at.

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

    For what it's worth I had this issue and none of these suggestions worked for me. It turns out that my problem was that SERVER_EMAIL was set to an address that the server (Webfaction) didn't recognise. If this site were hosted on Webfaction (as my other sites are), this wouldn't be a problem, but as this was on a different server, the Webfaction servers not only check the authentication of the email being sent, but also the From: value as well.

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

    Sorry if it is too naive, but in my case the emails were sent but were going directly to the SPAM folder. Before trying more complicated things check your SPAM folder first.

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

    If you are using or would want to use SendGrid, use the settings below in production.

    Install the package

    pip install sendgrid-django
    

    Add these settings in settings.py(production)

    DEBUG = False
    
    EMAIL_BACKEND = "sendgrid_backend.SendgridBackend"
    
    SENDGRID_API_KEY = "That you generate in sendgrid account"
    
    ADMINS = (
        ("Your Name", "your_email@company.com")
    )
    
    0 讨论(0)
  • 2020-12-08 09:38

    While likely not ideal, I have found using Gmail as the SMTP host works just fine. There is a useful guide at nathanostgard.com.

    Feel free to post your relevant settings.py sections (including EMAIL_*, SERVER_EMAIL, ADMINS (just take out your real email), MANAGERS, and DEBUG) if you want an extra set of eyes to check for typos!

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