我無法在我的谷歌應用程序中收到任何郵件。GAE + Python + Sendmail +表單=郵件無法正常工作
相關代碼:
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 <[email protected]>",
to = "personalAccount <[email protected]>",
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
你不能用'--enable_sendmail'部署一個應用程序。這是dev_appserver.py的SDK標誌。你究竟在做什麼?本地還是真的部署? – aschmid00 2012-07-19 16:54:31
真正部署在GAE上。那麼我在哪裏添加標誌呢?我是否需要指定我想要在谷歌應用程序儀表板中的某處使用郵件? – Dconversor 2012-07-19 17:06:58
你不需要做任何特別的事情;郵件API始終在生產中啓用。您不必在開發服務器上明確地打開它,因爲它旨在用於測試,並且95%的時間您不想實際發送消息。 – geoffspear 2012-07-19 17:16:32