Created
August 17, 2011 19:03
-
-
Save TheBHump/1152328 to your computer and use it in GitHub Desktop.
SMTP->SES Relay Server
This file contains hidden or 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
""" | |
SMTP->SES Relay Server | |
Author: Brian Humphrey, Loku.com | |
E-mail: [email protected] | |
Date: August 17, 2011 | |
A Lightweight SMTP server that accepts all messages and relays them to SES | |
Credit to http://www.doughellmann.com/PyMOTW/smtpd/ for a tutorial on smtpd with asyncore | |
""" | |
import smtpd | |
import asyncore | |
from boto.ses.connection import SESConnection | |
from email.parser import Parser | |
AWS_KEY = '<YOUR AWS KEY>' | |
AWS_SECRET_KEY = '<YOUR AWS SECRET KEY>' | |
SERVER_IP_ADDRESS = "<YOUR SERVER IP ADDRESS>" | |
SERVER_PORT = 1025 | |
class SESRelaySMTPServer(smtpd.SMTPServer): | |
def process_message(self, peer, mailfrom, rcpttos, data): | |
#Print the request information | |
print 'Receiving message from:', peer | |
print 'Message addressed from:', mailfrom | |
print 'Message addressed to :', rcpttos | |
print 'Message length :', len(data) | |
#Send out via SES | |
connection = SESConnection(aws_access_key_id = AWS_KEY, aws_secret_access_key = AWS_SECRET_KEY) | |
connection.send_raw_email(mailfrom, data) | |
server = SESRelaySMTPServer((SERVER_IP_ADDRESS, SERVER_PORT), None) | |
asyncore.loop() |
This file contains hidden or 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
""" | |
SMTP->SES Relay Server w/ Header Filter | |
Author: Brian Humphrey, Loku.com | |
E-mail: [email protected] | |
Date: August 17, 2011 | |
A Lightweight SMTP server that accepts all messages, removes the Error-To header which offends SES, then relays them to SES | |
Credit to http://www.doughellmann.com/PyMOTW/smtpd/ for a tutorial on smtpd with asyncore | |
""" | |
import smtpd | |
import asyncore | |
from boto.ses.connection import SESConnection | |
from email.parser import Parser | |
AWS_KEY = '<YOUR AWS KEY>' | |
AWS_SECRET_KEY = '<YOUR AWS SECRET KEY>' | |
SERVER_IP_ADDRESS = "<YOUR SERVER IP ADDRESS>" | |
SERVER_PORT = 1025 | |
class SESRelaySMTPServer(smtpd.SMTPServer): | |
def process_message(self, peer, mailfrom, rcpttos, data): | |
#Print the request information | |
print 'Receiving message from:', peer | |
print 'Message addressed from:', mailfrom | |
print 'Message addressed to :', rcpttos | |
print 'Message length :', len(data) | |
#Parse the message and remove headers that are offensive to SES | |
msg = Parser().parsestr(data) | |
if 'Errors-To' in msg: | |
del msg['Errors-To'] | |
#Send out via SES | |
connection = SESConnection(aws_access_key_id = AWS_KEY, aws_secret_access_key = AWS_SECRET_KEY) | |
connection.send_raw_email(mailfrom, msg.as_string()) | |
server = SESRelaySMTPServer((SERVER_IP_ADDRESS, SERVER_PORT), None) | |
asyncore.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment