pythongoogle-app-engineemail

google appengine receive email error


I'm in trouble. I'm playing now for a long time with receiving email in google apps but in my application Logs only get this:

0.1.0.20 - - [13/Jun/2013:08:42:23 -0700] "POST /_ah/mail/contact@myappid.appspotmail.com HTTP/1.1" 200 0 - - "myappid.appspot.com" ms=69 cpu_ms=0 cpm_usd=0.100008 app_engine_release=1.8.1 instance=00c61b117c2fb913155f167711d12979c818fd

My mail handler script schould be this: mailmain.py

import logging
import webapp2
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
from google.appengine.api import mail 

class LogSenderHandler(InboundMailHandler):
    def receive(self, mail_message):
        tobesent = mail_message.subject
        logging.info("From: " + mail_message.sender)
        logging.info("To:" + mail_message.to)
        logging.info("Subject: " + mail_message.subject)
        logging.info("Date: " + mail_message.date)

app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)

and my app.yaml is this:

application: myappid
version: 1
runtime: python27
api_version: 1
threadsafe: no

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /_ah/mail/contact@myappid.appsportmail.com
  script: mailmain.py 
  login: admin

- url: /.*
  script: mailmain.py

inbound_services:
- mail

I've tried playing with the script so I have many versions, some ending in this (if this matters) but really nothing works:

def main():
    app = webapp2.WSGIApplication([LogSenderHandler.mapping()], debug=True)
    run_wsgi_app(application)
if __name__ == "__main__":
    main()

I do have a favicon.ico uploaded as well.

Googled the error up for hours and hours and nothing works. Here on Stackoverflow I've found for similar error message solutions such as correct recieve into receive but this is not the case here. I've copied other solutions as well, also this from GITHUB so I believe this question is not a duplicate.


Solution

  • You mixing up CGI and WSGI. See Python27 getting started. Docs : https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingwebapp

    Yaml update :

    application: myappid
    version: 1
    runtime: python27
    api_version: 1
    threadsafe: false
    
    handlers:
    - url: /favicon\.ico
      static_files: favicon.ico
      upload: favicon\.ico
    
    - url: /_ah/mail/contact@myappid.appsportmail.com
      script: mailmain.app
      login: admin
    
    - url: /.*
      script: mailmain.app
    
    inbound_services:
    - mail
    

    With WSGI you do not need the run_wsgi_app stuff.

    And some background about CGI / WSGI: http://blog.notdot.net/2011/10/Migrating-to-Python-2-7-part-1-Threadsafe