from smtplib import SMTP f=file('send_challenge2', 'r') lngstr = f.read() f.close() students = eval(lngstr) s = SMTP() s.connect('smtp.webfaction.com') s.login('myname','simplepass') t_mes = """\ From: %s To: %s Subject: %s %s """ for stud in students: TO = [stud[0]] s_name = stud[2] FROM = stud[0].replace('@UDel.Edu', '@crypto.prof.ninja') for i in range(1,6): subject = "%s -- BlackHat Challenge %s" % (s_name[1:-1], str(i)) text = stud[3][i-1] message = t_mes % (FROM, ", ".join(TO), subject, text) s.sendmail(FROM, TO, message) s.quit()