我正在尝试使用this sample code和这些命令行选项发送电子邮件:
dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=xxx@gmail.com--smtp_password=k1tt3ns myapp
但是,当我的应用尝试发送电子邮件(在开发服务器上)时,我收到以下错误:
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 500, in __call__
handler.post(*groups)
File "C:\Documents and Settings\desk\Desktop\apps\temp\main.py", line 139, in post
""")
File "C:\Program Files\Google\google_appengine\google\appengine\api\mail.py", line 205, in send_mail
message.send(make_sync_call)
File "C:\Program Files\Google\google_appengine\google\appengine\api\mail.py", line 474, in send
make_sync_call('mail', self._API_CALL, message, response)
File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 68, in MakeSyncCall
apiproxy.MakeSyncCall(service, call, request, response)
File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub_map.py", line 240, in MakeSyncCall
stub.MakeSyncCall(service, call, request, response)
File "C:\Program Files\Google\google_appengine\google\appengine\api\apiproxy_stub.py", line 80, in MakeSyncCall
method(request, response)
File "C:\Program Files\Google\google_appengine\google\appengine\api\mail_stub.py", line 203, in _Send
self._SendSMTP(mime_message, smtp_lib)
File "C:\Program Files\Google\google_appengine\google\appengine\api\mail_stub.py", line 133, in _SendSMTP
smtp.login(self._smtp_user, self._smtp_password)
File "C:\Python26\lib\smtplib.py", line 552, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
SMTPException: SMTP AUTH extension not supported by server.
答案 0 :(得分:18)
dev_appserver.py不支持Gmail要求的TLS。您可以通过在api / mail_stub.py中添加几行来启用它:
# After smtp.connect(self._smtp_host, self._smtp_port)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
注意!这是快速而肮脏的解决方案。您应该添加某种标志来告诉它您是否要使用TLS,因为它并不总是需要。
答案 1 :(得分:4)
@Raymond
在终端中执行以下命令:
find / -name "mail_stub.py" -type f 2>/dev/null
在我的情况下,它返回:
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py
答案 2 :(得分:0)
不再需要其他方法:
在/appengine/api/mail_stub.py
if self._allow_tls and smtp.has_extn ('STARTTLS'):
smtp.starttls ()
在appengine sdk版本1.9.15上为我工作
答案 3 :(得分:0)
用于从应用程序发送电子邮件的Google帐户必须在https://security.google.com/settings中禁用某些安全设置。
如果您仍然遇到身份验证问题,则可能需要查看“设备和设备”。 https://security.google.com/settings/security/activity
的活动答案 4 :(得分:0)
对于任何在2018年或以后查找此答案的人:不再需要此解决方法。现在,您可以像原始海报那样使用命令了:
<script>
function myfunction() {
}
</script>
<img src='Myimg.jpg' onclick='myfunction()'>