使用python3发送qq邮件

import smtplib
from email.mime.text import MIMEText

def send_qq_email(subject, body, sender, auth, recipient):
# 连接到 QQ 邮箱的 SMTP 服务器
   #auth为在qq客户端生成的“生成授权码
    server = smtplib.SMTP_SSL("smtp.qq.com", 465)
# 登录邮箱
server.login(sender, password)
# 创建邮件正文
msg = MIMEText(body, "plain", "utf-8")
# 设置邮件主题
msg["Subject"] = subject
# 发送邮件
server.sendmail(sender, recipient, msg.as_string())
# 断开连接
server.quit()

if __name__ == '__main__':
send_qq_email("Hello", "Hello, world!", "839276@qq.com", auth=auth,
recipient= "jin@126.com")
posted @ 2022-12-23 16:20  yiwei1989100  阅读(69)  评论(0)    收藏  举报