Python批量发送邮件(带附件)
import smtplib
from email.message import EmailMessage
def send_mail(to_list, subject, body, attachment=None):
msg = EmailMessage()
msg['From'] = 'you@qq.com'
msg['To'] = ', '.join(to_list)
msg['Subject'] = subject
msg.set_content(body)
if attachment:
with open(attachment, 'rb') as f:
msg.add_attachment(f.read(), maintype='application',
subtype='octet-stream',
filename=attachment)
with smtplib.SMTP_SSL('smtp.qq.com', 465) as s:
s.login('you@qq.com', '你的授权码') # 注意是授权码,不是密码
s.send_message(msg)
send_mail(['a@x.com', 'b@x.com'], '周报', '请查收本周报告', '周报.xlsx')

更新时间:2026-09-14 13:14:33
上一篇:Python定时提醒 / 番茄钟