summaryrefslogtreecommitdiff
path: root/maconomy/mailer.py
blob: 46d0da1ebcdae4513c08ac600546396d242e6225 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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()