I am not able to receive any mail in my google application.
The relevant codes are:
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()
Note that there is a handler for the form '/on_send_form'.
The relevant html form:
<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>
Both the form and the handler uses the POST method. I deploy the GAE application with the option. --enable_sendmail
The logs in GAE say that the everything was ok.
I read the documentation and I don't know that I am missing.
Thank you in advance, DConversor
Your handlers in your WSGIApplication
constructor are in the wrong order; they're checked in the order they're given, and '/.*'
matches all URLS, so the '/on_send_form'
on is never checked. Put the catchall expression last.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.