[英]Django send_mail not working and returns 0 errors
My code executes fine from my localhost. 我的代码可以从本地主机正常执行。 However, when I try and run my django program from an ubuntu 16.04 server it doesn't work.
但是,当我尝试从ubuntu 16.04服务器运行django程序时,它不起作用。 I tried running the program in the shell and it doesn't return any errors.
我尝试在外壳中运行该程序,但不返回任何错误。 When I check my inbox I don't receive an email from the "from" address.
当我检查收件箱时,没有收到来自“发件人”地址的电子邮件。
I've tried sending the email to different addresses. 我尝试将电子邮件发送到其他地址。 I've also tried sending it using TLS instead of SSL.
我也尝试过使用TLS而非SSL发送它。 I also tried using smtplib to send the email instead of using django's send_mail.
我还尝试使用smtplib发送电子邮件,而不是使用django的send_mail。
Here is my code I'm using to send the email 这是我用来发送电子邮件的代码
send_mail('subject','my message','from_email@gmail.com',['to_email@xxxx.com'],fail_silently=False)
Here is my settings.py file 这是我的settings.py文件
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'from_email@gmail.com'
EMAIL_HOST_PASSWORD = '*******'
EMAIL_PORT = 465
You're missing a couple settings that Django/Gmail require. 您缺少Django / Gmail所需的几个设置。 Make sure to define EMAIL_BACKEND.
确保定义EMAIL_BACKEND。
Additionally for port 465 you need to enable SSL which is disabled by default. 此外,对于端口465,您需要启用默认情况下禁用的SSL。 https://docs.djangoproject.com/en/2.2/ref/settings/#email-use-ssl
https://docs.djangoproject.com/zh-CN/2.2/ref/settings/#email-use-ssl
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'from_email@gmail.com'
EMAIL_HOST_PASSWORD = '*******'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
Alternatively you can use TLS on 587 或者,您可以在587上使用TLS
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'from_email@gmail.com'
EMAIL_HOST_PASSWORD = '*******'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
One of the issues I encountered when using Gmail is that Gmail blocked the website from accessing it because the IP address was unrecognized and Gmail thought that someone had broken into my account. 使用Gmail时遇到的问题之一是Gmail阻止了该网站的访问,因为IP地址无法识别并且Gmail认为有人闯入了我的帐户。
Have you checked your account for alerts you may need to deal with? 您是否检查过帐户中可能需要处理的警报? We spent hours before doing that ourselves.
我们花了几个小时才自己做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.