[英]google-app-engine: Sending email from form data?
How do I generate a response and email for some form data. 如何生成一些表单数据的回复和电子邮件。 I tried something like:
我尝试了类似的东西:
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)
I'm mapping the script via app.yaml
and the script line: 我通过
app.yaml
和脚本行来映射脚本:
- url: /mail-me.py.*
script: mail-me.py
I'm invoking it using: dev_appserver.py ~root/whatever/
and browsing: localhost:8080
我使用以下命令调用它:
dev_appserver.py ~root/whatever/
并浏览: localhost:8080
I'm seeing no errors but there's no response page either in the browser 我没有看到任何错误,但浏览器中也没有响应页面
Also tried ( app.yaml
): 还尝试了(
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 -
Did you try browsing to localhost:8080/mail-me.py
? 您是否尝试浏览到
localhost:8080/mail-me.py
? That is what your routing uses to call your get()
method. 这就是路由用来调用
get()
方法的方式。
You don't need to include .py
in your URL. 您不需要在网址中包含
.py
。 Use ('/mail-me', My_Email_Class)
instead, and then browse to localhost:8080/mail-me
. 使用
('/mail-me', My_Email_Class)
代替,然后浏览到localhost:8080/mail-me
。
Figured it out: poor documentation! 想通了:糟糕的文档! This works:
这有效:
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
script: main.
剧本:主要。 app
应用程式
app = webapp2.WSGIApplication([(r'/', MainHandler),], debug=True)
app = webapp2.WSGIApplication([[(r'/',MainHandler),],debug = True)
app has to match, so you could expand that to application if you like or appxxx . 应用必须匹配,因此您可以根据需要将其扩展到应用或appxxx 。 py doesn't work though!
py不起作用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.