Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GAE+;Python+;Sendmail+;Form=邮件不工作_Python_Google App Engine_Sendmail - Fatal编程技术网

GAE+;Python+;Sendmail+;Form=邮件不工作

GAE+;Python+;Sendmail+;Form=邮件不工作,python,google-app-engine,sendmail,Python,Google App Engine,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(webap

我无法在我的谷歌应用程序中接收任何邮件

有关守则如下:

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()
从google.appengine.ext导入webapp
从google.appengine.ext.webapp.util导入运行\u wsgi\u应用程序
从google.appengine.api导入邮件
#将“inicio.html”网站设置为默认页面
类IndexHandler(webapp.RequestHandler):
def get(自我):
path='inicio.html'
如果self.request.url.endswith('/'):
路径=“%sinicio.html”%self.request.url
self.redirect(路径)
def post(自我):具有以下功能
self.get()
#发送包含表单字段的电子邮件
OnSendFormHandler类(webapp.RequestHandler):
def post(自我):
cf\u name=self.request.get('cf\u name')
cf\u email=self.request.get('cf\u email')
cf\u subject=self.request.get('cf\u subject')
cf\u body=self.request.get('cf\u message')
message=mail.EmailMessage(sender=“GAE帐户”,
至=“个人账户”,
主题=cf_主题,
车身=cf_车身)
message.send()
application=webapp.WSGIApplication([('/.*',IndexHandler),
('/on_send_form',OnSendFormHandler)],debug=True)
def main():
运行应用程序(应用程序)
如果名称=“\uuuuu main\uuuuuuuu”:
main()
请注意,表单“/on\u send\u 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> &nbsp; &nbsp; &nbsp;<a href="#" class="alt" onClick="document.getElementById('contacts-form').submit()">Enviar</a>
            </div>
          </div>
        </fieldset>
      </form>

名称:
电子邮件:
Asunto:
门萨耶:
表单和处理程序都使用POST方法。我使用该选项部署GAE应用程序。 --启用发送邮件

GAE的日志说一切都很好

我看了文件,不知道我失踪了

提前谢谢大家,,
DConversor

您的
WSGIApplication
构造函数中的处理程序顺序错误;它们是按照给定的顺序进行检查的,并且
'/.*
匹配所有URL,因此从不检查
'/on\u send\u form'
on。将catchall表达式放在最后。

您无法使用
--启用发送邮件
部署应用程序。这是dev_appserver.py的SDK标志。你到底在干什么?本地还是真正部署?真正部署在GAE上。那么我有权在哪里加国旗呢?我需要在google应用程序仪表板的某个地方指定我要使用mail吗?你不需要做任何特殊的事情;邮件API始终在生产时启用。您不必在dev服务器上显式地打开它,因为它是用于测试的,而且95%的时间您不想实际发送消息。不要这样认为。据我所知,它是默认启用的。您是否收到任何错误消息?如果没有,请尝试自己用日志模块记录。尝试一件事。将
更改为=“personalAccount”
-->
更改为=”existentAccount@gmail.com“
然后查看是否有效。这似乎是问题的原因。我改变了顺序,它似乎工作了,除了我现在发现的以下问题:文件“…main.py”,第32行,在post message.send()文件“/base/python\u runtime/python\u lib/versions/1/google/appengine/api/mail.py”,第900行,在send raiser\u MAP[e.application\u ERROR](e.ERROR\u detail)InvalidSenderError:未经授权的SenderKey,它可以工作!!我没有使用我的电子邮件地址。考虑到上面的main.py,我现在唯一的问题是,在发送邮件(按下提交按钮)后,我看到一个没有内容的白色页面。URL上写着“…appspot.com/on_send_form”。如何返回包含表单的页面?谢谢你们。@Dconversor:将
self.redirect('/')
添加到处理程序的末尾?非常感谢。现在一切都很完美。我也做了一些小改动。我将为其他有类似问题的人发布一个运行示例的链接。再次感谢Woobie和所有其他人的支持。DConversorI重新打开问题,是否可以在发送邮件和重定向后显示确认消息?我只想显示一个弹出窗口。我有一个php版本的表单,其中显示了一个确认弹出窗口,但现在使用python,我不知道如何只显示一个弹出窗口,而不显示一个全新的页面。非常感谢。