开发者

this is my Receiving Email code,but can't Receiving Email .. (google-app-engine)

开发者 https://www.devze.com 2022-12-28 15:00 出处:网络
import logging, email from google.appengine.ext import webapp from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
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


class LogSenderHandler(InboundMailHandler):
    def receive(self, message):
        _subject = message.subject
        _sender=message.sender
        bodies = message.bodies('text/plain')
        allBodies = ""
        #for body in bodies:
        #  allBodies = allBodies + "\n---------------------------\n" + body[1].decode()
        #m= mail.EmailMessage(sender="zjm1126@gmail.com ",subject="reply to "+_subject)
        #m.to = _sender
        #m.body =allBodies
        #m.send()
        message = mail.EmailMessage(sender="zjm1126@gmail.com",
                                        subject="Your account has been approved")
        message.to = _sender
        message.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
        """

        message.send()



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

app.yaml:

application: zjm1126

version: 1-2
runtime: python
api_version: 1

inbound_services:
- mail

handlers:
- url: /media
  static_dir: media

- url: /_ah/mail/.+ 
  script: handle_incoming_email.py 
  login: admin

- url: /
  script: a.py

- url: /sign
  script: a.py

- url: .*
  script: django_bootstrap.py

I use my email:zjm1126@gmail.c开发者_StackOverflowom send some words to ss@zjm1126.appspotmail.com

I can't get a Receiving Email, why?


I had the same problem after following the google tutorial as well. Thanks to this tute I discovered a rather important bit of code that slipped my mind and isn't in the google tutorial.

def main():
    run_wsgi_app(application)
if __name__ == "__main__":
    main()

Hope that helps.


It looks like you're trying to make code from mail send\receive tutorial to work. I used that tutorial also to check how mail service works and didn't have problems with it. What I could suggest doing is:

  1. decouple mail sending and receiving scripts as it seem like you're going to cycle it;

  2. I guess you already have the sending code somewhere else, but just in case, something has to send an email to ss@zjm1126.appspotmail.com to trigger the LogSenderHandler handler;

  3. You can check and debug your code locally by using zjm1126 development console. Try sending an email from here: http://localhost:8080/_ah/admin/inboundmail and put a breakpoint into the LogSenderHandler.receive method to see if it gets hit and what's going on after that;

  4. In your yaml I see other handlers but webapp.WSGIApplication has only LogSenderHandler mappings. It might be the reason why those other scripts are not getting executed;

other than that your code and yaml look fine and should work

hope this helps, regards


Everything looks fine - your handler is returning a 200 OK. If you're not receiving the email it's sending, try logging the values you're using so you can check that everything's valid and what you expect it to be.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号