Skip to content

Instantly share code, notes, and snippets.

@darragh
Created October 16, 2009 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darragh/211682 to your computer and use it in GitHub Desktop.
Save darragh/211682 to your computer and use it in GitHub Desktop.
application: letsgateway
version: 1
runtime: python
api_version: 1
inbound_services:
- mail
handlers:
- url: /emails
script: outgoing.py
secure: always
- url: /_ah/mail/.+
script: incoming.py
login: admin
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 urlfetch
import urllib
class MailHandler(InboundMailHandler):
def receive(self, message):
content_type, encoded = message.bodies(content_type='text/plain').next()
body = encoded.decode()
sender = message.sender
subject = message.subject
urlfetch.fetch("http://localhost:3000/emails/handle_incoming", urllib.urlencode({'body':body, 'sender':sender, 'subject':subject}), urlfetch.POST)
application = webapp.WSGIApplication([MailHandler.mapping()], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import mail
class OutgoingEmailHandler(webapp.RequestHandler):
def post(self):
message = mail.EmailMessage(sender="someone@somewhere.com")
message.subject = self.request.get('subject')
message.to = self.request.get('to')
message.body = self.request.get('body')
message.send()
application = webapp.WSGIApplication([('/emails', OutgoingEmailHandler)], debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment