public
Last active

  • Download Gist
tlsrelay.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.