I am writing a python script to help a friend's after-school program to send tuition bill to parents. I have student tuition in a {studentName, tuition}
dict, and parent contacts in another {studentName, parentContact}
dict, due to different attendance, each student's tuition number is different. I have the following function to intend to send individual email with different tuition info to individual parent. The problem I am having is, when I run my python script, from python shell, when I print it out, it looks like different email with different tuition numbers was intended for different parents, but the actual email each parent received was the same copy of the first student's tuition info. Here is my send email function:
def send_mail(studentParentContact, studentTuition):
msg=MIMEMultipart()
msg['Subject'] = 'Your kid After-school Program Tuition Bill'
msg['From'] = FLPEmail #after-school program's email address
# Send the message via SMTP server
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(username, PASSWORD) #after-school program gmail login
for student in studentParentContact:
ParentEmail=studentParentContact[student]
tuition=studentTuition[student]
msg['To'] = ParentEmail
body="Hi, \nThe tuition for "+student+' is '+'$'+ str(tuition)
msg.attach(MIMEText(body, 'plain'))
text=msg.as_string()
print FLPEmail, ParentEmail, text
s.sendmail(FLPEmail, ParentEmail, text)
s.quit()
So instead of sending student A's tuition info to A's parent, student B's tuition info to B's parent, student C's tuition info to C's parent, the actual outcome right now is that it is sending A's tuition info to A and B and C's parents. Same tuition to all parents. How do I fix this? Thank you very much!