-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailing.py
36 lines (27 loc) · 952 Bytes
/
mailing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
import smtplib
class Mailer:
'''Mailer for notifications'''
def __init__(self, user, host):
self.sender = user + '@' + host
self.host = host
def sendNotification(self, toAddr, subject, body):
'''
Given a recipient list, message subject and body,
send an e-mail with those parameters
'''
if not self.host:
return
receivers = []
for receiver in toAddr.split(';'):
receivers.append("<" + receiver + "@" + host + ">")
message = "From: No Reply Balance <[email protected]>\n" \
"To: " + ';'.join(receivers) + "\n" \
"Subject: " + subject + "\n" + \
body
try:
smtpObj = smtplib.SMTP(self.host, 25, 'localhost')
smtpObj.sendmail(self.sender, receivers, message)
except smtplib.SMTPException:
print "error: email notification failed"
sys.exit(0)