Google App Engine使用Mail API时出现问题

时间:2015-08-06 18:48:38

标签: google-app-engine

您好我的联系人页面上有一个发布方法的联系表单,并希望能够使用Mail API从我的Google应用引擎应用程序发送外发邮件所以我决定使用邮件API并将自己注册为我的开发人员控制台上的授权发件人并启动了命令--enable_sendmail = yes applicationID但是当我测试它时,它给了我这个错误。我仍然是谷歌应用引擎的新手,不知道为什么会这样。

"INFO 2015-08-06 18:44:50,935 mail_stub.py:142] MailService.Send
     From: abdallahozaifa19527@gmail.com
  To: Hozaifa
  Subject: Test
/bin/sh: 1: sendmail: not found
ERROR    2015-08-06 18:44:50,944 mail_stub.py:263] Error sending mail using sendmail: [Errno 32] Broken pipe" 
import os
import webapp2
import jinja2
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):
            self.write(self.render_str(template, **kw))

 class MainPage(Handler):
    def get(self):
               self.render("index.html")

class AboutPage(Handler):
    def get(self):
               self.render("about.html")                   

class ProjectsPage(Handler):
    def get(self):
               self.render("projects.html")

class ExperiencePage(Handler):
    def get(self):
               self.render("experience.html")                  

class ContactPage(Handler):
    def get(self):
               self.render("contact.html")
    def post(self):
        name = self.request.get('name')
        email = self.request.get('email')
        message = self.request.get('message')

        if (name and email and message):
            message = mail.EmailMessage(sender="abdallahozaifa19527@gmail.com", subject="Test")
            message.to = "Hozaifa<abdallahozaifa19527@gmail.com>"
            message.send()
        else:
            self.write("It didnt work!")


app = webapp2.WSGIApplication([('/', MainPage),
                            ('/about.html', AboutPage),
                            ('/projects.html', ProjectsPage),
                            ('/experience.html', ExperiencePage), 
                            ('/contact.html', ContactPage)])

1 个答案:

答案 0 :(得分:0)

我的代码有效,但它不适用于谷歌应用引擎SDK,因为SDK没有发送邮件,我试图使用SDK测试它,问题解决了!