SMTPRoutes 1.2.9

A simple, Sinatra inspired, SMTP routing server
SMTPRoutes is a lightweight SMTP server built on top of Secure-SMTPD.

It's what you'd get if Sinatra and SMTP had a baby.

Routes

Routes are specified via a regex provided in the route kwarg.

from smtproutes import Route

class ExampleRoute(Route):
 def my_route(self, route=r'myroute@.*'):
 print self.mailfrom.email


When invoked a route will have access to the following instance variables:

- self.message the parsed email message.
- self.mailfrom a contact object indicating who the message was received from.
- self.tos an array of contact objects extracted from the To field.
- self.ccs an array of contact objects extracted from the CC field.
- self.bccs an array of contact objects extracted from the BCC field.

Any named groups specified in the route regex will be availble as instance variables.

class ExampleRoute(Route):

 def open_route(self, route=r'(?Popen)@(?P.*)'):
 print "%s at %s sent the message: \n\n %s" % (
 self.prefix,
 self.suffix,
 self.message
 )


Sender Authentication

Email is vulnerable to spoofing attacks. SMTPRoutes allows you to provide an authentication object to protect against these.

An authentication class can be provided in the sender_auth kwarg of a route.

def spf_route(self, route=r'(?Pspf)@(?P.*)', sender_auth=SPFAuth):
 print "%s at %s sent the message: \n\n %s" % (
 self.prefix,
 self.suffix,
 self.message
 )


Currently the following sender authentication methods are supported:

- DKIMAuth authenticates using a DKIM signature.
- SPFAuth authenticates using an SPF record.
- GmailSPFAuth authenticates against Google's SPF records, regardless of sender (useful for Google Apps).

You can provide multiple authentication approaches in the sender_auth kwarg, if any pass the route will be called:

def google_apps_spf_route(self, route=r'(?Pspf_google)@(?P.*)', sender_auth=[SPFAuth, GmailSPFAuth]):
 print "%s at %s sent the message: \n\n %s" % (
 self.prefix,
 self.suffix,
 self.message
 )


Running a Server

The server is a thin abstraction on top of Secure-SMTPD (https://github.com/bcoe/secure-smtpd) hence:

- SSL is supported.
- Basic SMTP authentication is supported.

Create an instance of the server using the same options specified in the secure-smtpd project.

from smtproutes import Server

server = Server(('0.0.0.0', 25), None)

Once the server is created, you can register routes with it and start it running:

from example_route import ExampleRoute
server.add_route(ExampleRoute)
server.start()


The server will now be listening on port 25 for inbound SMTP messages.

last updated on:
December 26th, 2011, 15:26 GMT
price:
FREE!
developed by:
Benjamin Coe
homepage:
github.com
license type:
MIT/X Consortium License 
category:
ROOT \ Communications \ Email

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT