blob: 16d57738d022c2881664baa5f74b718b3109d5f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
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 e:
print(u"Error sending mail to: {}. Got error: {}".format(to, str(e)))
def close(self):
self.server.quit()
|