import smtplib from email.mime.text import MIMEText #文本 from email.mime.multipart import MIMEMultipart#附件 from email.header import Header #配置一些头信息 #nggrhflurdivdcfd #nxphnvljccppdcgj授权码 #smtp.qq.com #2431320433@qq.com sender="2962194949@qq.com" #发送人的邮件 recevises=["2431320433@qq.com"] #接收人的邮箱列表,可以写多个 mail_host="smtp.qq.com" #stmp邮箱的服务器地址 password="nxphnvljccppdcgj" #本人邮箱授权码 subject="这是一封测试邮件" #本次邮箱发送的主题 #发送文本测试 #message=MIMEText("这是一个计算器的测试邮件。。。。。","plain","utf-8") message=MIMEMultipart() #附件管理器,能添加N个附件 #设置发送邮件的一些配置 message["From"]=Header("wangsai","utf-8") message["To"]=Header("测试","utf-8") message["Subject"]=Header(subject,"utf-8") message.attach(MIMEText("这是附件","plain","utf-8")) #构造附件1,传送当前目录下的test.txt文件 att1=MIMEText(open('计算器的报告.html','rb').read(),'base64','utf-8') att1["Content-Type"]='application/octet-stream' #这里的filename可以任意写,写什么名字,邮件显示什么名字 att1["Content-Disposition"]='attachment;filename="computer.html"' message.attach(att1) try: smtp=smtplib.SMTP() #smtp发送器 smtp.connect(mail_host,587) smtp.login(sender,password) smtp.sendmail(sender,recevises,message.as_string()) print("发送成功") except Exception as error: print("邮件发送失败!",error)
计算器的发送邮件报告
最新推荐文章于 2024-07-27 12:20:46 发布