上一篇文章写了发邮件给单个人,这篇文章实现发送给多个人。
主要修改
_user = "xx@qq.com" #发件人邮箱 _pwd = "授权码" #发件人授权码 _recer=["aa@qq.com","bb@163.com","cc@qq.com"] #收件人列表
import smtplib from email.mime.text import MIMEText _user = "xx@qq.com" _pwd = "授权码" # _to = "yy@163.com" _recer=["aa@qq.com","bb@163.com","cc@qq.com"] msg = MIMEText("今天是2021年11月16日 周二 晴天") msg["Subject"] = " don't panic" msg["From"] = _user msg["To"] = ",".join(_recer)#区别与给一个人发,指定某个人用 msg["To"] = _to 多个人用.join try: s=smtplib.SMTP_SSL("smtp.qq.com",465) s.login(_user,_pwd) s.sendmail(_user,_recer,msg.as_string()) s.quit() print("Success!") except smtplib.SMTPException as e: print("Failed,%s"%e)