问题
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