Created
December 31, 2011 05:21
-
-
Save lxneng/1542985 to your computer and use it in GitHub Desktop.
AmazonSMTPServer
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
#!/usr/bin/python | |
import smtpd | |
import email | |
import asyncore | |
from boto.ses import SESConnection | |
class AmazonSMTPServer(smtpd.SMTPServer): | |
amazonSES = SESConnection() | |
def process_message(self, peer, mailfrom, rcpttos, data): | |
data = email.message_from_string(data) | |
# Amazon SES don't support 'Organization' header, which is created | |
# by email_template module | |
if 'Organization' in data: | |
del data['Organization'] | |
data = data.as_string() | |
result = self.amazonSES.send_raw_email(mailfrom, data, rcpttos) | |
server = AmazonSMTPServer(('127.0.0.1', 9090), None) | |
asyncore.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment