Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created January 21, 2011 22:06
Show Gist options
  • Save jordansissel/790522 to your computer and use it in GitHub Desktop.
Save jordansissel/790522 to your computer and use it in GitHub Desktop.
Example of using email as a gateway to other protocols with Lamson
import logging
from lamson.routing import route, route_like, stateless
from config.settings import relay
from lamson import view
import httplib
import httplib, urllib
@route("(address)@(host)", address=".+", host=".+\.loggly.(?:net|com)$")
def START(message, address=None, host=None):
print "Got message to %s@%s: %r " % (address, host, message)
conn = httplib.HTTPConnection("%s:80" % host)
print " => Sending to http://%s/inputs/%s" % (host, address)
conn.request("POST", "/inputs/%s" % address, str(message.to_message()))
response = conn.getresponse()
# TODO(sissel): Shove this into a mail queue if the response is failure
# So we can retry later, maybe?
print response.status, response.reason
data = response.read()
conn.close()
return None
@route("(address)@(host)", address=".+", host=".+")
def START(message, address=None, host=None):
print "WARNING: Got message to invalid address %s@%s: %r " % (address, host, message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment