I am trying to send Email using this sample code and these command-line options:
我正在尝试使用此示例代码和这些命令行选项发送电子邮件:
dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=xxx@gmail.com--smtp_password=k1tt3ns myapp
However, I receive the following error when my app tries to send e-mail (on the development server):
但是,当我的应用程序尝试发送电子邮件(在开发服务器上)时,我收到以下错误:
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.
5 个解决方案
#1
dev_appserver.py doesn't support TLS which is required by Gmail. You can enable it by adding a few lines in api/mail_stub.py:
dev_appserver.py不支持Gmail要求的TLS。您可以通过在api / mail_stub.py中添加几行来启用它:
# After smtp.connect(self._smtp_host, self._smtp_port)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
Note! That's the quick and dirty solution. You should add some kind of flag to tell it whether you want to use TLS or not, as it is not always desired.
注意!这是快速而肮脏的解决方案。你应该添加某种标志来告诉它你是否要使用TLS,因为它并不总是需要。
#2
@Raymond
Execute the following command in the Terminal:
在终端中执行以下命令:
find / -name "mail_stub.py" -type f 2>/dev/null
In my case it returns:
在我的情况下,它返回:
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py
#3
The other methods are no longer necessary:
其他方法不再需要:
Setting the following in /appengine/api/mail_stub.py
在/appengine/api/mail_stub.py中设置以下内容
if self._allow_tls and smtp.has_extn ('STARTTLS'):
smtp.starttls ()
works for me on appengine sdk version 1.9.15
在appengine sdk版本1.9.15上为我工作
#4
The Google account being used to send emails from an application must have some security settings disabled in https://security.google.com/settings.
用于从应用程序发送电子邮件的Google帐户必须在https://security.google.com/settings中禁用某些安全设置。
- Disable access for less secure apps : Access for less secure apps: Turn On
禁用访问安全性较低的应用:访问不太安全的应用:启用
If you continue to have authentication issues you may have to review the Devices & activity at the https://security.google.com/settings/security/activity
如果您仍然遇到身份验证问题,则可能需要查看https://security.google.com/settings/security/activity上的设备和活动
#5
For anyone looking up this answer in 2018 or later: this workaround is no longer needed. You can now use the command like the original poster wrote it:
对于在2018年或之后查找此答案的任何人:不再需要此解决方法。您现在可以像原始海报一样使用命令:
dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=xxx@gmail.com --smtp_password=yyy myapp
#1
dev_appserver.py doesn't support TLS which is required by Gmail. You can enable it by adding a few lines in api/mail_stub.py:
dev_appserver.py不支持Gmail要求的TLS。您可以通过在api / mail_stub.py中添加几行来启用它:
# After smtp.connect(self._smtp_host, self._smtp_port)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
Note! That's the quick and dirty solution. You should add some kind of flag to tell it whether you want to use TLS or not, as it is not always desired.
注意!这是快速而肮脏的解决方案。你应该添加某种标志来告诉它你是否要使用TLS,因为它并不总是需要。
#2
@Raymond
Execute the following command in the Terminal:
在终端中执行以下命令:
find / -name "mail_stub.py" -type f 2>/dev/null
In my case it returns:
在我的情况下,它返回:
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/mail_stub.py
#3
The other methods are no longer necessary:
其他方法不再需要:
Setting the following in /appengine/api/mail_stub.py
在/appengine/api/mail_stub.py中设置以下内容
if self._allow_tls and smtp.has_extn ('STARTTLS'):
smtp.starttls ()
works for me on appengine sdk version 1.9.15
在appengine sdk版本1.9.15上为我工作
#4
The Google account being used to send emails from an application must have some security settings disabled in https://security.google.com/settings.
用于从应用程序发送电子邮件的Google帐户必须在https://security.google.com/settings中禁用某些安全设置。
- Disable access for less secure apps : Access for less secure apps: Turn On
禁用访问安全性较低的应用:访问不太安全的应用:启用
If you continue to have authentication issues you may have to review the Devices & activity at the https://security.google.com/settings/security/activity
如果您仍然遇到身份验证问题,则可能需要查看https://security.google.com/settings/security/activity上的设备和活动
#5
For anyone looking up this answer in 2018 or later: this workaround is no longer needed. You can now use the command like the original poster wrote it:
对于在2018年或之后查找此答案的任何人:不再需要此解决方法。您现在可以像原始海报一样使用命令:
dev_appserver.py --smtp_host=smtp.gmail.com --smtp_port=25 --smtp_user=xxx@gmail.com --smtp_password=yyy myapp