首页 > 编程语言 > 详细

Python发送QQ邮件

时间:2019-11-26 22:51:42      阅读:77      评论:0      收藏:0      [点我收藏+]

一、开启QQ邮箱SMTP服务

技术分享图片

import smtplib
from email.mime.text import MIMEText
from email.header import Header

smtp = "smtp.qq.com"
sender = "2282310940@qq.com"
receiver = "1328497946@qq.com"

# pwd = ""
pwd = ‘你的授权码‘
title = "邮件的标题"
contents = "邮件内容"

try:
	message = MIMEText(contents, "plain", "utf-8")
	message[‘From‘] = Header(sender, "utf-8")
	message[‘To‘] = Header(receiver, "utf-8")
	message[‘Subject‘] = Header(title, "utf-8")
	opt = smtplib.SMTP_SSL(smtp, 465)
	opt.login(sender, pwd)
	opt.sendmail(sender, receiver, message.as_string())
	opt.quit()
	print("邮件发送成功")
except Exception as e:
	print(e)

 测试一下,发送成功。

Python发送QQ邮件

原文:https://www.cnblogs.com/1328497946TS/p/11938517.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!