Django mail sending error with DEBUG=False

痴心易碎 提交于 2021-01-01 07:42:25

问题


In my Django website I have a contact form. If the contact form is submitted there need to be send an email to user and admin. When DEBUG is True the email was sent. But when DEBUG is False it won't send mail. Here I am using Django mail.

settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'email@gmail.com'
EMAIL_HOST_PASSWORD = 'abc123'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER

回答1:


First, when DEBUG is True the email was sent, is the email was sent by SMTP server or it just print the email in the console? Are you also using the SMTP emailbackend for your EMAIL_BACKEND settings or you are using the console.backend for your development settings? Because usually you should set your Email_backend to console.backend when you are in development mood. Second, when you switch to production mood, the application won't send mail, Did you get any errors? And did you test the google smtp server connection works?(check this for detail: https://docs.djangoproject.com/en/1.11/topics/email/#smtp-backend) Sometimes you have to set the ssl_certfile and ssl_keyfile for the google smtp server depends on your google smtp security level.



来源:https://stackoverflow.com/questions/47093584/django-mail-sending-error-with-debug-false

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!