-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailer.py
49 lines (36 loc) · 1.41 KB
/
Mailer.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
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Created on Oct. 12 2011
@author: Jason MacWilliams
"""
import subprocess
def sendEmail(addrs, subject, message):
print("Sending email (%s) to addresses: %s" % (subject, addrs))
subprocess.Popen('echo "%s" | mailx -s "%s" %s' % (message, subject, addrs), shell=True, executable="/bin/bash")
# cmd = echo "message" | mailx -s "subject" addresses
# XXX: we might want to attach the logfile or something else here. In that case the order of
# the print statement and the sendmail should be reversed so the print statement doesn't appear
# in the log
class EmailMessage:
def __init__(self, subject="", addrs=[]):
if type(addrs) != list:
return
self.subject = subject
self.addrs = addrs
self.message = ""
def addAddress(self, addr):
if type(addr) == str and not addr in self.addrs:
self.addrs.append(addr)
def removeAddress(self, addr):
if type(addr) == str and addr in self.addrs:
self.addrs.remove(addr)
def setSubject(self, subject):
self.subject = subject
def clearMessage(self):
self.message = ""
def addLine(self, line):
self.message = self.message + "\n" + line
def addString(self, string):
self.message = self.message + string
def send(self):
if self.subject and self.addrs:
sendEmail(" ".join(self.addrs), self.subject, self.message)