9 sender_header = 'mail-merge-sender@mit.edu'
12 def dictize_line(header, line,):
14 for key, elem in zip(header, line, ):
18 def setup_sendmail_smtp():
22 def sendmail_smtp(addrs, text):
24 smtp.sendmail(sender_header, addrs, text, )
25 smtp_funcs = (setup_sendmail_smtp, sendmail_smtp, )
27 def sendmail_cmd(addrs, text):
28 args = ["/usr/lib/sendmail", "--", ]
30 proc = subprocess.Popen(args, stdin=subprocess.PIPE)
31 proc.communicate(text)
32 cmd_funcs = (lambda: True, sendmail_cmd)
34 setup_sendmail, sendmail = smtp_funcs
35 setup_sendmail, sendmail = cmd_funcs
37 if __name__=='__main__':
38 print "Syntax: $script $cc_addr $template $recipients"
41 email_file = sys.argv[2]
42 email = open(email_file, 'r').read()
43 reader = csv.reader(open(sys.argv[3]))
44 header = reader.next()
47 dct = dictize_line(header, line, )
50 sendmail([dct['email'], cc_addr, ], text, )