我无法在谷歌应用程序中收到任何邮件。
相关代码是:
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中的日志表示一切正常。
我阅读了文档,但我不知道我错过了。
提前谢谢你, DConversor
答案 0 :(得分:2)
您的WSGIApplication
构造函数中的处理程序顺序错误;它们按照给定的顺序进行检查,'/.*'
匹配所有网址,因此永远不会检查'/on_send_form'
。把这个表达式放在最后。