I am trying to send my class their quiz results with their First Name and Score using an excel file (pandas df). However, how do I loop through the df line by line to extract individual names and scores?
The df looks like this:
The following output obviously only works for the first line item of the df as I have specified index of 0 for First Name and Score both.
email_list = [abc@gmail.com, def@gmail.com, ghi@gmail.com]
email['from'] = 'Zoya Aqib'
email['subject'] = 'Corporate Rating Quiz'
for recipient in email_list:
email['To'] = recipient
email.set_content(html.substitute({'name' : df['First Name'][0], 'score' : df['Score'][0]}))
with smtplib.SMTP(host='smtp.gmail.com',port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login('****@gmail.com','****')
smtp.send_message(email)
del email['To']
print('all done!')
Edit: for those suggesting iterating over df, this error is received when i try to do so: "smtplib.SMTPRecipientsRefused: {}" And the email ends up only being sent to first recipient