python之邮件提醒

list1 = ['邮箱1', '邮箱2', '邮箱3']
for username_recv in list1:
mailserver = "smtp.163.com" # 邮箱服务器地址
username_send = '发送方邮箱名' # 邮箱用户名
password = '邮箱名' # 邮箱密码:需要使用授权码
# username_recv = #收件人,多个收件人用逗号隔开
mail = MIMEText('内容', 'plain', 'utf-8')
mail['Subject'] = '标题'
mail['From'] = username_send # 发件人
mail['To'] = username_recv # 收件人;[]里的三个是固定写法
smtp = smtplib.SMTP(mailserver, port=25) # 连接邮箱服务器,smtp的端口号是25
smtp.login(username_send, password) # 登录邮箱
smtp.sendmail(username_send, username_recv, mail.as_string()) # 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
smtp.quit() # 发送完毕后退出smtp
原文地址:https://www.cnblogs.com/yp19970/p/12611692.html