[英]Google App Engine Error - in check_initialized raise MissingRecipientsError()
I'm trying to setup a static webpage on the Google Cloud Platform (GCP) with a contact-form. 我正在尝试使用联系表在Google Cloud Platform(GCP)上设置静态网页。 I originally used php but it doesn't work with GCP. 我最初使用的是php,但不适用于GCP。 In my research, LINK , I tried using the provided code and got the following error: 在我的研究LINK中 ,我尝试使用提供的代码,并得到以下错误:
<!doctype html> <html> <head> <title>Leave a message</title> <meta charset="utf-8"/> </head> <body> <form method="post"> <input name="mail" placeholder="Enter your email"> <br/> <input name="subject" placeholder="Subject"> <br/> <input name="name" placeholder="Enter your name"> <br/> <textarea name="message" style="height:200px; width:500px;" placeholder="Enter your message"> </textarea> <br/> <input type="submit" value="Send"/> </body> </html>
INFO 2018-01-26 11:17:08,904 module.py:833] default: "POST / HTTP/1.1" 500 2317
File "F:\Programs\google-cloud-sdk\platform\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "F:\Documents\Programming\html\perrykowebdesigns2\contact.py", line 48, in post
message.send()
File "F:\Programs\google-cloud-sdk\platform\google_appengine\google\appengine\api\mail.py", line 1129, in send
message = self.ToProto()
File "F:\Programs\google-cloud-sdk\platform\google_appengine\google\appengine\api\mail.py", line 1385, in ToProto
message = super(EmailMessage, self).ToProto()
File "F:\Programs\google-cloud-sdk\platform\google_appengine\google\appengine\api\mail.py", line 1067, in ToProto
self.check_initialized()
File "F:\Programs\google-cloud-sdk\platform\google_appengine\google\appengine\api\mail.py", line 1370, in check_initialized
raise MissingRecipientsError()
MissingRecipientsError
I'm relatively new, so I don't understand the error and how to fix it. 我是相对较新的人,所以我不了解该错误以及如何解决。 If you understand how to fix it, please provide the solution. 如果您了解如何解决,请提供解决方案。
Thanks! 谢谢!
import webapp2
import jinja2
import os
from google.appengine.api
import mail
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape = True)
class Handler(webapp2.RequestHandler):
def write(self, * a, * * kw):
self.response.out.write( * a, * * kw)
def render_str(self, template, * * params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, * * kw):`enter code here`
self.write(self.render_str(template, * * kw))
class contact(Handler):
def get(self):
self.render("contact.html")
# template = jinja_env.get_template('contact.html')# def get(self): #self.response.out.write(self.template.render())
def post(self): #takes input from user
userMail = self.request.get("mail")
subject = self.request.get("subject")
name = self.request.get("name")
userMessage = self.request.get("message")
message = mail.EmailMessage(sender = "7dayclimber@gmail.com", subject = "Test")
# not tested
if not mail.is_email_valid(userMail):
self.response.out.write("Wrong email! Check again!")
message.to = userMail
message.body = ""
"Thank you!
You have entered following information:
Your mail: % s
Subject: % s
Name: % s
Message: % s ""
" %(userMail,subject,name,userMessage)
message
self.response.out.write("Message sent!")
app = webapp2.WSGIApplication([('/', contact)], debug = True)
You're missing the to
argument in the mail.EmailMessage()
call. 您在mail.EmailMessage()
调用中缺少to
参数。
From google.appengine.api.mail module : 来自google.appengine.api.mail模块 :
An EmailMessage can be built completely by the constructor: EmailMessage可以由构造函数完全构建:
EmailMessage(sender='sender@nowhere.com', to='recipient@nowhere.com', subject='a subject', body='This is an email to you').Send()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.