Created
May 9, 2012 17:24
-
-
Save adambard/2646930 to your computer and use it in GitHub Desktop.
Inbox.py example
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
""" | |
Proxy smtp to a starttls server with authentication, from a local | |
connection. | |
""" | |
from inbox import Inbox | |
from smtplib import SMTP | |
inbox = Inbox() | |
SMTP_HOST = 'mail.example.com' | |
SMTP_USERNAME = 'username' | |
SMTP_PASSWORD = 'password' | |
@inbox.collate | |
def handle(to, sender, body): | |
""" | |
Forward a message via an authenticated SMTP connection with | |
starttls. | |
""" | |
conn = SMTP(SMTP_HOST, 25, 'localhost') | |
conn.starttls() | |
conn.ehlo_or_helo_if_needed() | |
conn.login(SMTP_USERNAME, SMTP_PASSWORD) | |
conn.sendmail(sender, to, body) | |
conn.quit() | |
inbox.serve(address='0.0.0.0', port=4467) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment