Permalink
Browse files

Added send_invite_emails tool. It is useful to avoid sending emails f…

…rom AppEngine.
  • Loading branch information...
1 parent 29142e9 commit bf2ddb1a7af663790493790ae47a2170ef851105 @bboe bboe committed May 10, 2012
Showing with 38 additions and 1 deletion.
  1. +1 −1 README.md
  2. +37 −0 send_invite_emails.py
View
@@ -1,4 +1,4 @@
-# UCSB Computer Science Course Lists
+# course_lists.py
## Overview
View
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+import json
+import os
+import smtplib
+import sys
+
+
+def main():
+ try:
+ data = json.load(open(sys.argv[1]))
+ except (IndexError, IOError):
+ print 'Usage: {} emails_json'.format(os.path.basename(sys.argv[0]))
+ sys.exit(1)
+ except ValueError:
+ print '{!r} is not a valid json file'.format(sys.argv[1])
+ sys.exit(1)
+
+ from_email = 'Computer Science Lead TA <leadta@cs.ucsb.edu>'
+ subject = 'Computer Science Midterm TA Evaluations'
+ template = data['template']
+
+ smtp = smtplib.SMTP()
+ smtp.connect('stamps.cs.ucsb.edu')
+
+ for info in data['emails']:
+ body = template.format(student=info['name'], body=info['output'])
+ msg = 'From: {}\nTo: {}\nSubject: {}\n\n{}'.format(
+ from_email, info['email'], subject, body)
+ smtp.sendmail(from_email, info['email'], msg)
+ sys.stdout.write('.')
+ sys.stdout.flush()
+ print
+ smtp.quit()
+
+
+if __name__ == '__main__':
+ sys.exit(main())

0 comments on commit bf2ddb1

Please sign in to comment.