Skip to content

Instantly share code, notes, and snippets.

@douglasgoodwin
Created December 5, 2013 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save douglasgoodwin/7810592 to your computer and use it in GitHub Desktop.
Save douglasgoodwin/7810592 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import imaplib
import csv
from email import message_from_string
import time
srv = imaplib.IMAP4_SSL("imap.gmail.com")
srv.login('joe@gmail.com', 'joepw')
srv.select('[Gmail]/Drafts')
def send_m(first_name, last_name, emailaddr, attendance, grade):
message = message_from_string("""To: "%s %s" <%s>
Subject: [CSSM231] Your Grade
Hello %s,
This email contains your current score for CSSM231 "All That Glitters".
attendance: %s (should be 70 or higher to pass)
grade: %s
The grade gets translated into HP/P/LP according to the following scale:
85+ HP
75-84 P
60-74 LP
Please contact me if you have any questions.
-Thanks,
-Doug
""" % (first_name, last_name, emailaddr, first_name, attendance, grade))
srv.append("[Gmail]/Drafts",
'',
imaplib.Time2Internaldate(time.time()),
str(message))
ifile = open('scores.csv', "rb")
csvreader = csv.reader(ifile)
for row in csvreader:
"""first_name,last_name,email,grade,attendance"""
first_name = row[0]
last_name = row[1]
emailaddr = row[2]
attendance = row[3]
grade = row[4]
print first_name, last_name, emailaddr, first_name, attendance, grade
send_m(first_name, last_name, emailaddr, attendance, grade)
time.sleep(1)
"""
scores.csv like this:
first_name,last_name,email,attendance,grade
"""
first_name last_name email attendance grade
fonz shark jump@happydays.com 77 88
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment