2

I'm writing application on GAE that can parse and store incoming mails. I've prepared some simple code for email parsing, but something goes wrong, when I try to simulate e-mail recieveing from admin dev console on local dev server:

/develop/google_appengine/google/appengine/runtime/wsgi.py", line 193, in Handle
    result = handler(self._environ, self._StartResponse)
TypeError: 'module' object is not callable
INFO     2012-05-08 16:14:43,516 dev_appserver.py:2891] "POST /_ah/mail/[email protected] HTTP/1.1" 500 -

app.yaml:

application: mailhandler
version: 1
runtime: python27
api_version: 1
threadsafe: true

inbound_services:
- mail

handlers:
- url: /_ah/mail/.+ 
  script: email_handler
  login: admin

email_handler.py:

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

from models import DataStoreManager

class LogSenderHandler(InboundMailHandler):
    # Receiving new mail message and parsing it
    def receive(self, mail_message):                                                                                                                      
        manager = DataStoreManager()
        instance = manager.get_instance_by_email(mail_message.sender.lowercase())

        email_key = manager.store_email(instance, instance.user, mail_message, mail_message.attachments)

What I'm doing wrong?

1
  • can you please post the whole traceback?
    – aschmid00
    May 10, 2012 at 16:00

2 Answers 2

7

i think what happens is that in your app.yaml you define the module/file as the script instead of an application, the module is not callable of course.

change the app.yaml definition to:

handlers:
- url: /_ah/mail/.+ 
  script: email_handler.application
  login: admin

and add this line at the end of email_handler.py

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

here the docs: https://developers.google.com/appengine/docs/python/mail/receivingmail

3

The problem is you don't have declare a WSGIApplication for your handler LogSenderHandler.

You have to read about that on: https://developers.google.com/appengine/docs/python/python27/using27

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

from models import DataStoreManager

class LogSenderHandler(InboundMailHandler):
    # Receiving new mail message and parsing it
    def receive(self, mail_message):                                                                                                                      
        manager = DataStoreManager()
        instance = manager.get_instance_by_email(mail_message.sender.lowercase())

        email_key = manager.store_email(instance, instance.user, mail_message, mail_message.attachments)

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

After that you have to specify the WSGI application in your app.yaml

handlers:
- url: /_ah/mail/.+ 
  script: email_handler.application
  login: admin

Note: As is written in the documentation, the class InboundMailHandler has a special method mapping helps you to declare the map of URL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.