import smtplib
from email.mime.text import MIMEText
from email.header import Header
# email 用于构建邮件内容
# 发信方的信息:发信邮箱,QQ 邮箱授权码'zrkuilidyjamjfbe'
from_addr = '1154922383@qq.com'
password = 'zrkuilidyjamjfbe'
# 收信方邮箱
#to_addr = input('请输入收件邮箱:')#手动输入收件地址
to_addrs = ['3192331052@qq.com','1154922383@qq.com','hejinguimax@hotmail.com']#批量发送的邮件地址
# 发信服务器
smtp_server = 'smtp.qq.com'
text='''These violent delights have violent ends And in their triumph die, like fire and powder,Which, as they kiss, consume.'''
# 邮箱正文内容,第一个参数为内容,第二个参数为格式(plain 为纯文本),第三个参数为编码
msg = MIMEText(text,'plain','utf-8')
msg['From'] = Header('from_addr')
msg['To'] = Header(",".join(to_addrs))
msg['Subject'] = Header('python测试')
# 开启发信服务,这里使用的是加密传输
server = smtplib.SMTP_SSL(smtp_server)
server.connect(smtp_server,465)
# 登录发信邮箱
server.login(from_addr, password)
# 发送邮件
try:
server.sendmail(from_addr, to_addrs, msg.as_string())
print('恭喜,发送成功')
except:
print('发送失败,请重试')
# 关闭服务器
server.quit()