我尝试在django 1.8中使用smtp.gmail.com
发送邮件
我的settings.py
包含:
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST='smtp.gmail.com'
EMAIL_PORT=465
EMAIL_HOST_USER = 'sarath4coding'
EMAIL_HOST_PASSWORD = '*********'
DEFAULT_EMAIL_FROM = 'sarath4coding@gmail.com'
from django.core import mail
mail.send_mail('subject','message','sarath4coding@gmail.com',['sarath4coding@gmail.com'])
但得到了这个错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
return mail.send()
File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
new_conn_created = self.open()
File "/home/manager/dj1.8/local/lib/python2.7/site-packages/django_smtp_ssl.py", line 14, in open
self.connection.login(self.username, self.password)
File "/usr/lib/python2.7/smtplib.py", line 622, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (534, '5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuze\n5.7.14 2FDKQt2Dlo2vqFIvbr6DnBItwWvh9DChPwbeTZO66N91gzmiA437Vqs80cZ9-8u13vxq5a\n5.7.14 bVahzO_BQcZ53yKbJ-YbAlmFE1XIK7MfH97O0wI1lvzpTG_WAHuTIBF0HD1GA2icUoUemt\n5.7.14 ErZn4qb942aAIMG103FnrzLp4txXTbXC-wGLpaz5yvnUN5thahvv3-RiIVW8F1QddZKZlg\n5.7.14 qQKpqWw56zr1AcO2s_oaBEt556fQ> Please log in via your web browser and\n5.7.14 then try again.\n5.7.14 Learn more at\n5.7.14 https://support.google.com/mail/answer/78754 kx14sm6579665pab.0 - gsmtp')
我尝试了文件中所说的一切,并遵循了许多建议的解决方案。
例如https://accounts.google.com/DisplayUnlockCaptcha,启用低安全性应用程序等。
但我还是出错了
有人能告诉我如何正确配置Django 1.8来使用Gmail发送邮件吗?
7条答案
按热度按时间uqjltbpv1#
我在settings.py:
views.py:
标签:https://accounts.google.com/DisplayUnlockCaptcha
并确保打开安全性较低的应用程序的权限。
pqwbnv8z2#
请记住:
转到您的Google帐户设置,找到安全->帐户权限->访问不太安全的应用程序,启用此选项。
关于此选项:https://support.google.com/accounts/answer/6010255
1tuwyuhd3#
我测试了一下,在django 1.8中运行得很好:
首先,你应该检查this link,由谷歌提供,你做了:)
请注意,由于一些我不知道的奇怪原因,您必须在
view.py or shell
中编写这样的代码:这也是我在
setting.py
文件中的设置:snvhrwxg4#
在www.example.com文件中替换settings.py:
由
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
w7t8yxp55#
在www.example.com中settings.py更改此
dtcbnfnu6#
这对我很有效:
settings.py
解锁验证码:https://accounts.google.com/DisplayUnlockCaptcha
views.py
du7egjpx7#
我在Django 1.11中使用了这个
在settings.py
在view.py
并后藤https://myaccount.google.com/u/0/security?hl=en以启用不太安全的应用程序访问