Last active
August 29, 2015 14:07
-
-
Save asadoughi/3d374aa43579726bd64e 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 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