diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 15:32:39 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 15:32:39 -0400 |
commit | 384e322f974534c1c734db144633e3c3e002b1f8 (patch) | |
tree | 1637267cea4cb5166677f272e97b19ce8331a36c /run/emailer.py | |
parent | 4162cc0c57de22566efa6e2dab224909279f2a47 (diff) |
Added option to send email when experiments complete.
Diffstat (limited to 'run/emailer.py')
-rw-r--r-- | run/emailer.py | 28 |
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 @@ | |||
1 | import os | ||
2 | import pwd | ||
3 | import smtplib | ||
4 | import socket | ||
5 | |||
6 | class 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)) | ||