python发QQ邮件

2022/3/8 20:15:00

本文主要是介绍python发QQ邮件,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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("无法发送")

                   

这篇关于python发QQ邮件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程