Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle App Engine w/ Django - InboundMailHandler appears to only work once
    text
    copied!<p>I'm writing an app for Google App Engine (with Python and Django) that needs to receive email and add some elements of the received email messages to a datastore. I am a very novice programmer.</p> <p>The problem is that the script I specify to handle incoming email appears to only run once (until the script is touched).</p> <p>Sending a test email from the local admin console to, say, 'test@downloadtogo.appspotmail.com' causes an entity to be added to the local datastore correctly.</p> <p>Sending a second, third, etc. test email has no effect - the entity is not added.</p> <p>'Touching' <code>handle_incoming_email.py</code> (which I understand to mean adding or deleting a space and then saving), <em>then</em> sending another test email, will cause the entity to be added correctly.</p> <p>app.yaml:</p> <pre> application: downloadtogo version: 1 runtime: python api_version: 1 handlers: - url: /static static_dir: static - url: /.* script: main.py - url: /_ah/mail/.+ script: handle_incoming_emaril.py login: admin inbound_services: - mail </pre> <p>handle_incoming_email.py:</p> <pre><code> from downloadtogo.models import Email import logging, email import wsgiref.handlers import exceptions from google.appengine.api import mail from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext.webapp.mail_handlers import InboundMailHandler class MailHandler(InboundMailHandler): def receive(self, message): email = Email() email.from_address = message.sender email.put() def main(): application = webapp.WSGIApplication([MailHandler.mapping()], debug=True) wsgiref.handlers.CGIHandler().run(application) main() </code></pre> <p>models.py:</p> <pre> <code> from appengine_django.models import BaseModel from google.appengine.ext import db class Email(db.Model): from_address = db.StringProperty() to_address = db.StringProperty() body = db.StringProperty(multiline=True) added_on = db.DateTimeProperty(auto_now_add=True) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload