pythonSTMP发送邮件



# 如果我们本机没有 sendmail 访问,也可以使用其他服务商的 SMTP 访问(QQ、网易、Google等)。
import smtplib
from email.mime.text import MIMEText
from email.header import Header

# 第三方 SMTP 服务
#授权码 ywsospiyjslmeaca
mail_host="smtp.qq.com" #设置服务器
mail_name="xxxxxx" #用户名
mail_pass="xxxxxxxx" #口令

sender='xxxxxxx'
receivers=['xxxxxxxxx']

message=MIMEText('python邮件发送测试','plain','utf-8')
message['From']=Header('自由','utf-8')
message['To']=Header('白鹿','utf-8')

subject='python stmp 邮件发送测试'
message['Subject']=Header(subject,'utf-8')


stmpObj=smtplib.SMTP()
stmpObj.connect(mail_host,25)
stmpObj.login(mail_name,mail_pass)
stmpObj.sendmail(sender,receivers,message.as_string())



猜你喜欢

转载自blog.csdn.net/qq_52605986/article/details/121771629
今日推荐