python – 不能将Django设置为使用smtp.gmail.com

我一直试图让django与gmail的smtp服务器一起发送邮件,但我总是得到这个追溯。任何帮助将不胜感激。

—– settings.py —–

EMAIL_HOST = 'smtp.gmail.com'

EMAIL_HOST_USER = 'user@gmail.com'

EMAIL_HOST_PASSWORD = 'your-password'

EMAIL_PORT = 587

EMAIL_USE_TLS = True

—- python shell —–

from django.core.mail import EmailMessage

email = EmailMessage(‘Mail Test’, ‘This is a test’, to=[‘somemail@something.com’])

email.send()

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/fiodorovich/Envs/fdict/lib/python2.7/site-packages/django/core/mail/message.py", line 251, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/fiodorovich/Envs/fdict/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 86, in send_messages
sent = self._send(message)
File "/home/fiodorovich/Envs/fdict/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 104, in _send
email_message.message().as_string())
File "/usr/local/lib/python2.7/smtplib.py", line 701, in sendmail
raise SMTPSenderRefused(code, resp, from_addr)
SMTPSenderRefused: (530, '5.7.0 Must issue a STARTTLS command first. z15sm10449686anl.15', 'webmaster@localhost')

编辑:做出修改建议的新错误。 shell将不会执行,我收到此错误消息

**EMAIL_HOST_USER  = 'some.account@gmail.com'**
 ^
SyntaxError: invalid syntax
我最近设置了这个,并且有一个稍微不同的settings.py配置。

移动:

EMAIL_USE_TLS = True 

到EMAIL_HOST上方

加:

DEFAULT_FROM_EMAIL = 'user@gmail.com'
SERVER_EMAIL = 'user@gmail.com'
http://stackoverflow.com/questions/7877452/cannot-set-django-to-work-with-smtp-gmail-com

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:python – 不能将Django设置为使用smtp.gmail.com