上图为要发送的内容存为xls格式 第一列是邮箱第二列是邮件定制内容 场景是批量发送运单号 第二列是伪装的运单号
参考https://blog.csdn.net/LeoPhilo/article/details/89074232博客教你怎么发一封邮件这里改装成发多封邮件
代码如下
#!/usr/bin/env python # coding=utf-8 import sys import xlrd import smtplib from email.mime.text import MIMEText from email.header import Header from_addr='xxx@xxx.com'#自己的邮箱 password = '对应授权码' to_addr = [] bag_number = [] workbook = xlrd.open_workbook('TEST.xls') execel_sheet = workbook.sheet_by_index(0) nrows = execel_sheet.nrows ncols = execel_sheet.ncols for i in range(0,nrows): to_addr.append(execel_sheet.row(i)[0].value) bag_number.append(execel_sheet.row(i)[1].value) #print(to_addr) #print(bag_number) smtp_server = 'smtp.qq.com' server = smtplib.SMTP_SSL() server.connect(smtp_server,465) server.login(from_addr,password) #print(nrows) for i in range(0,nrows): msg = MIMEText('你的运单号码为:'+bag_number[i]+' 请注意查收。','plain','utf-8') msg['From'] = Header(from_addr) msg['To'] = Header(to_addr[i]) msg['Subject'] = Header('铅球中奖运单编号') server.sendmail(from_addr,to_addr[i],msg.as_string()) server.quit()