python发qq邮件相对比较简单,网上教程一大把;固定套路,后面封装看自己怎么方便可以怎样进行封装;原版代码如下:
\"\"\"
# -*- coding : utf-8 -*-
# @Time : 2021/3/28 18:54
# @Author : gan
\"\"\"
#导入三个固定短信邮箱模块
import smtplib
from email.mime.text import MIMEText
from email.header import Header
mail_host = \"smtp.qq.com\"
mail_user = \"111111@qq.com\" #发送方邮箱
mail_pwd = \"abcdefghijklmno\" #发送方邮箱的授权码
sender = \"1111@qq.com\"
receivers = [\"11111@qq.com\",\"22222@qq.com\"] #多位接收人
message = MIMEText(\"测试结果正文\",\"plain\",\"utf-8\")
message[\"From\"] = Header(\"自动化测试小组\",\"utf-8\")
message[\"To\"] = Header(\"开发小组\",\"utf-8\")
subject = \"测试结果邮件\"
message[\'Subject\'] = Header(subject,\"utf-8\")
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host,25)
smtpObj.login(mail_user,mail_pwd)
smtpObj.sendmail(sender,receivers,message.as_string())
print(\"邮件发送成功\")
except smtplib.SMTPException:
print(\"无法发送\")
来源:https://www.cnblogs.com/ganfd/p/15981525.html
本站部分图文来源于网络,如有侵权请联系删除。