在App Engine开发服务器上通过SMTP服务器发送电子邮件时出错

在App Engine开发服务器上通过SMTP服务器发送电子邮件时出错

问题描述:

我正在尝试使用此示例代码发送电子邮件和这些命令行选项:

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.


dev_appserver.py不支持需要的TLS通过Gmail。您可以通过在api / mail_stub.py中添加几行来启用它:

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:

# After smtp.connect(self._smtp_host, self._smtp_port)
smtp.ehlo()
smtp.starttls()
smtp.ehlo()

注意!这是一个快速而肮脏的解决方案。您应该添加一些标志来告诉它是否要使用TLS,因为并不总是需要。

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.