google-app-engine:从表单数据发送电子邮件?

时间:2015-11-08 04:28:11

标签: python google-app-engine google-app-engine-python

如何为某些表单数据生成响应和电子邮件。我试过像:

import webapp2
from google.appengine.api import mail

MAIN_PAGE_HTML = """\
<html>
  <body>
   <h1>response to GET</h1>
  </body>
</html>
"""

class My_Email_Class(webapp2.RequestHandler):
      def get(self):
          user_address = self.request.get("email")
          user_name = self.request.get("name")

          if not mail.is_email_valid(user_address):
              pass

          message = mail.EmailMessage()
          message.sender = 'xyz@xyz.com'
          message.to = 'abcd@abcd.com'
          message.subject = "Website:" + str(user_name + user_email)
          message.body = """\
Hi
"""
          message.send()

          self.response.write(MAIN_PAGE_HTML)

app = webapp2.WSGIApplication([('/mail-me.py', My_Email_Class),], debug=True)

我正在通过app.yaml和脚本行映射脚本:

- url: /mail-me.py.*
  script: mail-me.py

我正在使用dev_appserver.py ~root/whatever/调用它 和浏览:localhost:8080

我看到没有错误,但浏览器中没有响应页面

还试过(app.yaml):

application: hello
version: 1
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /.*
  script: main.py

main.py

import os
import webapp2
class MainHandler(webapp2.RequestHandler):
  def get(self):
    print 'Content-Type: text/plain'
    print ''
    print 'Hello, world!'

application = webapp2.WSGIApplication([(r'/', MainHandler)], debug=True)

INFO 2015-11-10 06:29:51,805 module.py:794] default: "GET / HTTP/1.1" 200 -

2 个答案:

答案 0 :(得分:0)

您是否尝试过浏览RelativeLayout?这就是您的路由用于调用<Scrollview> <LinearLayout> <RelativeLayout> **everything else** </RelativeLayout> <Button .. /> </LinearLayout> </Scrollview> 方法的内容。

您无需在网址中加入localhost:8080/mail-me.py。请改用get(),然后浏览到.py

答案 1 :(得分:0)

想出来:糟糕的文档! 这有效:

import os
import webapp2

class MainHandler(webapp2.RequestHandler):
  def get(self):
    print 'Content-Type: text/plain'
    print ''
    print 'Hello, world!'

app = webapp2.WSGIApplication([(r'/', MainHandler),], debug=True)


application: hello
version: 1
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /.*
  script: main.app
  

脚本:main。 app

     

app = webapp2.WSGIApplication([(r&#39; /&#39;,MainHandler),],debug = True)

应用必须匹配,因此您可以将其扩展为应用(如果您愿意)或 appxxx py 虽然不起作用!