使用模块yagmail,直接pip install yagmail安装即可import yagmail
username = 'xxxxxx@qq.com' # 发件人的邮箱
password = 'xxxxxx' # 生成授权码,qq、163、126都是授权码 发件人的密码
mail_sever='smtp.qq.com'
m=yagmail.SMTP(user=username,password=password,host=mail_sever)
to=['chenjie930818@qq.com']#接收人
cc=['chenjie930701@163.com']#抄送
m.send(to=to,cc=cc,
subject='chenjieeeee', #主题
contents='111111方法恢复恢复',#正文
attachments='日志.py'#附件
)