如何在Google App Engine中使用Python发送邮件(不工作)

时间:2014-06-05 12:33:44

标签: python google-app-engine email

我在谷歌应用程序引擎中使用jQuery和Python有一个应用程序,它允许用户发布内容...我在Python中有一个恢复密码处理程序,我希望这个处理程序通过发送该用户来处理查询/数据一封电邮。但它似乎不起作用:

class RecoverHandler(webapp2.RequestHandler):
    def get(self):
        #email = self.request.get('#email')
        usr = self.request.get('email')#or email
        dob = self.request.get('dob')
        name = self.request.get('maidenName')
        callback = self.request.get('callback')
        #get user from database
        #user = User.get_by_id(#email)
        user = User.get_by_id(usr)
        #if user exists check for correct password
        dobx = user.dob
        namex = user.maidenName
        if user:
            if dobx == dob:
                if namex == name:
                    self.response.write(callback + '({"response":"login Complete"})')

                    mail.send_mail(sender="Example.com Support <support@example.com>",
                    to="Albert Johnson <Albert.Johnson@example.com>",
                    subject="Your account has been approved",
                    body="""
                    Dear Albert:
                    Your example.com account has been approved.  You can now visit
                    http://www.example.com/ and sign in using your Google Account to
                    access new features.Please let us know if you have any questions.The example.com Team""")

                else:
                    self.response.write(callback + '({"response":"login incomplete"})')
            else:
                self.response.write(callback + '({"response":"login Password incorrect"})')
        else:
            self.response.write(callback + '({"response":"login not found"})')

1 个答案:

答案 0 :(得分:0)

user = User.get_by_id(usr)

您的实体的ID是否真的是他们的电子邮件地址?你能添加一些日志吗?如果您的ID不是电子邮件地址,则user.dobuser.maidenName会出现NoneType错误。

dobx = user.dobnamex = user.maidenName应该放在if内,因此如果找不到用户,则不会抛出错误。