其他分享
首页 > 其他分享> > 发送邮件

发送邮件

作者:互联网

#pyemail邮件处理

import smtplib
from email.mime.text import MIMEText #用于构建邮箱内容
msg_from="rhag20220508@126.com" #发件人
password="XWCNBJQGFRDZOEVI"#客户端授权码
msg_to="3248736782@qq.com"#收件人

#构造邮箱内容
subject="0508测试邮件"
content="你中奖了!5毛钱!"
msg=MIMEText(content)#邮件内容对象
msg["Subject"]=subject
msg["From"]=msg_from
msg["To"]=msg_to
#发送邮件
smtpobj=smtplib.SMTP_SSL(" smtp.126.com",465) #smtpob smtp对象
smtpobj.login(msg_from,password) #登录
smtpobj.sendmail(msg_from,msg_to,str(msg))#发送邮件
print("发送成功!")
smtpobj.quit()#关闭邮件程序

标签:发送,smtpobj,MIMEText,msg,com,邮件
来源: https://www.cnblogs.com/rhax072828/p/16245465.html