Mass Mail Sending script
Last semester, I was honored to be a teaching assistant of digital image processing. I need to send the corresponding score to each student after checking each assignment. Hope to this code may help other teaching assistants
#copyleft Mei_Jiaming 2020
#@ShanghaiTech University
import pandas as pd
import numpy as np
from string import Template
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import socket
MY_ADDRESS='XXXX@outlook.com'
PASSWORD='XXXXXX'
data=pd.read_excel('hw4total.xlsx')
length=data.shape[0]
message_template=Template('Hello $name, your homework4 has a total score of $Total, including $Basic for the Basic, $Bonus for the Bonus.')
#message_template=Template('$name $email $Q1 $Q2 $Total')
s = smtplib.SMTP(host='smtp-mail.outlook.com', port=587)
s.ehlo()
s.starttls()
s.login(MY_ADDRESS,PASSWORD)
for i in range(length):
data_i=dict(data.loc[i])
msg = MIMEMultipart() # create a message
message = message_template.substitute(data_i)
print(data_i)
msg['From']=MY_ADDRESS
msg['To']=data_i['email']
msg['Subject']="Homework4 score"
msg.attach(MIMEText(message, 'plain'))
s.send_message(msg)
print("SENT EMAIL TO ", data_i['name'])
del msg
#add waiting time
print('type anything or nothing and press Enter (Prevent sending blocking ):')
x = input()
print('Hello, ' + x)
s.quit()