Skip to content

Instantly share code, notes, and snippets.

@asadoughi
Last active August 29, 2015 14:07
Show Gist options
  • Save asadoughi/3d374aa43579726bd64e to your computer and use it in GitHub Desktop.
Save asadoughi/3d374aa43579726bd64e to your computer and use it in GitHub Desktop.
class EmailNotifier(object):
def __init__(self):
self.smtp_server = config.CFG.get("email_notifier", "smtp_server")
self.smtp_port = config.CFG.getint("email_notifier", "smtp_port")
self.sender = config.CFG.get("email_notifier", "username")
self.password = config.CFG.get("email_notifier", "password")
def notify(self, recipients, subject, body=""):
session = smtplib.SMTP(self.smtp_server, self.smtp_port)
session.ehlo()
session.starttls()
session.login(self.sender, self.password)
for recipient in recipients:
msg = MIMEText(StringIO().read())
msg["Subject"] = subject
msg["From"] = self.sender
msg["To"] = recipient
email = msg.as_string() + body
session.sendmail(self.sender, recipient, email)
session.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment