Created
January 21, 2011 22:06
-
-
Save jordansissel/790522 to your computer and use it in GitHub Desktop.
Example of using email as a gateway to other protocols with Lamson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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