【发布时间】:2012-07-19 16:43:56
【问题描述】:
我无法在我的 Google 应用程序中接收任何邮件。
相关代码为:
main.py
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail
# Sets the "inicio.html" website as the default page
class IndexHandler(webapp.RequestHandler):
def get(self):
path='inicio.html'
if self.request.url.endswith('/'):
path = '%sinicio.html'%self.request.url
self.redirect(path)
def post(self):have the following
self.get()
# Sends an email with the fields of the form
class OnSendFormHandler(webapp.RequestHandler):
def post(self):
cf_name=self.request.get('cf_name')
cf_email=self.request.get('cf_email')
cf_subject=self.request.get('cf_subject')
cf_body=self.request.get('cf_message')
message = mail.EmailMessage(sender="GAE Account <validAccount@appspot.gserviceaccount.com>",
to = "personalAccount <existentAccount@gmail.com>",
subject = cf_subject,
body = cf_body)
message.send()
application = webapp.WSGIApplication([('/.*', IndexHandler),
('/on_send_form', OnSendFormHandler)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
请注意,表单“/on_send_form”有一个处理程序。
相关的html表单:
<form action="/on_send_form" method="post" id="contacts-form">
<fieldset>
<div class="grid3 first">
<label title="Escriba su nombre y apellidos">Nombre:<br />
<input type="text" name="cf_name" value=""/>
</label>
<label title="Escriba la dirección de correo electrónico donde quiere que le enviemos la respuesta a su consulta">E-mail:<br />
<input type="email" name="cf_email" value=""/>
</label>
<label title="Escriba la razón principal de su mensaje">Asunto:<br />
<input type="text" name="cf_subject" value="" title="Escriba la razón principal de su mensaje"/>
</label>
</div>
<div class="grid5">Mensaje:<br />
<textarea name="cf_message" title="Escriba su consulta con detalle. Le responderemos a la dirección de correo electrónico indicada en un plazo máximo de 24 horas"></textarea>
<div class="alignright">
<a href="#" class="alt" onClick="document.getElementById('contacts-form').reset()">Limpiar Campos</a> <a href="#" class="alt" onClick="document.getElementById('contacts-form').submit()">Enviar</a>
</div>
</div>
</fieldset>
</form>
表单和处理程序都使用 POST 方法。我使用该选项部署 GAE 应用程序。 --enable_sendmail
GAE 中的日志显示一切正常。
我阅读了文档,但我不知道我错过了。
提前谢谢你, D转换器
【问题讨论】:
-
您无法使用
--enable_sendmail部署应用程序。那是 dev_appserver.py 的 SDK 标志。你到底在做什么?本地部署还是实际部署? -
真正部署在 GAE 上。那么我应该在哪里添加标志?我是否需要在 google 应用程序仪表板的某处指定我要使用邮件?
-
你不需要做任何特别的事情;邮件 API 始终在生产中启用。您不必在开发服务器中明确打开它,因为它是用于测试的,而且 95% 的时间您都不想实际发送消息。
-
不这么认为。据我所知,它默认启用。你收到任何错误信息吗?如果不尝试使用日志记录模块自己记录。
-
尝试一件事。更改
to = "personalAccount <existentAccount@gmail.com>"-->to = "existentAccount@gmail.com"看看是否可行。
标签: python google-app-engine sendmail