import smtplib from email.mime.text import MIMEText class Mailer: def __init__(self, config): self.me = config.get("mail", "from") server_addr = config.get("mail", "server") self.server = smtplib.SMTP(server_addr) def send(self, to, subject, body): msg = MIMEText(body,'html', _charset='utf8') msg['To']=to msg['From']=self.me msg['Subject'] = subject try: self.server.sendmail(self.me, to, msg.as_string()) except Exception as e: print(u"Error sending mail to: {}. Got error: {}".format(to, str(e))) def close(self): self.server.quit()