如何GAE(python)需要接收邮件并在留言板上发帖然后发送邮件给所有用户?

时间:2011-12-24 19:00:19

标签: python google-app-engine email

有人知道我的节目有什么问题吗? 我写了一个main.py.并将其发布到GAE。 但是当我在GAE上键入一些词时,它无法向表中的作者发送邮件

 
    class Send(webapp.RequestHandler):         
       def send(self):

          mail.send_mail(sender=users.get_current_user(), 
                             to=Greeting.author.all(),#Table 
                           body=self.request.get('content'))

          self.redirect("/")

    application = webapp.WSGIApplication([
      ('/', MainPage),
      ('/sign', Guestbook),##click sign to use Guestbook
      ('/sign', Send)
    ], debug=True)

我写了一个handle_incoming_email.py  尝试发送邮件到123 @ http:appid.appspotmail.com 但我看不到表格中的任何内容,也无法向表格中的作者发送邮件


    class ReceiveEmail(InboundMailHandler):
        def receive(self,message):
            logging.info("Received email from %s" % message.sender)
            plaintext = message.bodies(content_type='text/plain')

            mail.send_mail(sender=mail_message.sender, 
                               to=m.Greeting.author.all(), 
                             body=plaintext)

    application = webapp.WSGIApplication([
      ReceiveEmail.mapping()
    ], debug=True)

1 个答案:

答案 0 :(得分:2)

要接收电子邮件,请参阅http://code.google.com/appengine/docs/python/mail/receivingmail.html

要发送电子邮件,请参阅http://code.google.com/appengine/docs/python/mail/sendingmail.html

例如

import logging, email
from google.appengine.ext import webapp 
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler 
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail

class LogSenderHandler(InboundMailHandler):
    def receive(self, mail_message):
        # post it to message board
        # assuming Message is a table
        text = "\n".join(mail_message.bodies('text/plain'))
        msg = Message(text=text, sender=mail_message.sender)
        msg.put()

        # email msg to list of users
        mail.send_mail(sender=mail_message.sender, to=[list of user], body=text)