aboutsummaryrefslogtreecommitdiffstats
path: root/run/emailer.py
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-04-10 15:32:39 -0400
committerJonathan Herman <hermanjl@cs.unc.edu>2013-04-10 15:32:39 -0400
commit384e322f974534c1c734db144633e3c3e002b1f8 (patch)
tree1637267cea4cb5166677f272e97b19ce8331a36c /run/emailer.py
parent4162cc0c57de22566efa6e2dab224909279f2a47 (diff)
Added option to send email when experiments complete.
Diffstat (limited to 'run/emailer.py')
-rw-r--r--run/emailer.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/run/emailer.py b/run/emailer.py
new file mode 100644
index 0000000..6d66da2
--- /dev/null
+++ b/run/emailer.py
@@ -0,0 +1,28 @@
1import os
2import pwd
3import smtplib
4import socket
5
6class Emailer(object):
7 def __init__(self, target):
8 user = pwd.getpwuid(os.getuid())[0]
9 host = socket.gethostname()
10
11 self.sender = "%s@%s" % (user, host)
12 self.target = target
13
14 self.body = "\r\n".join(["From: %s" % self.sender,
15 "To: %s" % target,
16 "Subject: Test Completed!", "", "{}"])
17
18 self.mail = smtplib.SMTP("localhost")
19
20 # Hopefully crash if the server is not running
21 self.mail.ehlo()
22
23 def close(self):
24 self.mail.quit()
25
26 def send(self, text):
27 self.mail.sendmail(self.sender, [self.target],
28 self.body.format(text))