Created
August 8, 2009 02:01
-
-
Save galvez/164275 to your computer and use it in GitHub Desktop.
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
class TLSRelay(server.Relay): | |
def __init__(self, host='127.0.0.1', port=25, debug=0, use_tls=False, auth={}): | |
self.use_tls = use_tls | |
self.auth = auth | |
self.hostname = host | |
self.port = port | |
self.debug = debug | |
def deliver(self, message, To=None, From=None): | |
relay_host = smtplib.SMTP(self.hostname, self.port) | |
relay_host.set_debuglevel(self.debug) | |
relay_host.ehlo() | |
if self.use_tls: | |
relay_host.starttls() | |
if len(self.auth.keys()): | |
relay_host.login(self.auth['username'], self.auth['password']) | |
relay_host.sendmail(From or message['From'], To or message['To'], str(message)) | |
relay_host.quit() | |
def __repr__(*args, **kargs): | |
if self.use_tls: | |
return "<Relay to (%s:%d TLS)>" % (self.hostname, self.port) | |
else: | |
server.Relay.__repr__(*args, **kargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment