有人知道我的程序有什么问题吗?
我写了一个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)
最佳答案
有关接收电子邮件的信息,请参见http://code.google.com/appengine/docs/python/mail/receivingmail.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)