Python利用SMTP发送邮件
【阿里云】爆款云产品,新客特惠全年最低价,云服务器低至0.4折起,11.1开售
【腾讯云】爆款1核2G云服务器首年48元,还有iPad Pro、Bose耳机、京东卡等你来抽!
【华为云】上云特惠巨划算,免单抽奖享豪礼
【七牛云】爆款云产品全年最低价,热门产品 0 元秒杀,参与抽奖赢新款 iPhone
1.安装pyemail模块
pip install pyemail
2.代码如下
import smtplib
from email.mime.text import MIMEText
masg_from="xxxxxxx@qq.com" #发送方地址
pwd="xxxxxxxxxxx" #密码,QQ邮箱需获取客户端授权码
to="xxxxxxxxxx@qq.com" #收件方地址
subject="这是Python发送的邮件" #邮件主题
content="<h1>xxxxxxxxxx</h1>" #消息内容
#构造邮件
msg=MIMEText(content,"html","utf-8")
msg["Subject"]=subject
msg["From"]=masg_from
msg["To"]=to
#发送邮件
try:
ss=smtplib.SMTP_SSL("smtp.qq.com",465) #smtp服务端地址和端口号
ss.login(masg_from,pwd) #登陆邮箱
ss.sendmail(masg_from,to,msg.as_string()) #发送
print("发送成功!")
except Exception as e:
print("发送失败!详情:",e)
版权属于:LeeYD · Blog
本文标题:Python利用SMTP发送邮件
本文链接:https://www.leeyiding.com/archives/18/
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 4.0 许可协议
若转载本文,请标明出处并告知本人
【阿里云】爆款云产品,新客特惠全年最低价,云服务器低至0.4折起,11.1开售
【腾讯云】爆款1核2G云服务器首年48元,还有iPad Pro、Bose耳机、京东卡等你来抽!
【华为云】上云特惠巨划算,免单抽奖享豪礼
【七牛云】爆款云产品全年最低价,热门产品 0 元秒杀,参与抽奖赢新款 iPhone