Skip to content

Instantly share code, notes, and snippets.

@adambard
Created May 9, 2012 17:24
Show Gist options
  • Save adambard/2646930 to your computer and use it in GitHub Desktop.
Save adambard/2646930 to your computer and use it in GitHub Desktop.
Inbox.py example
"""
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