Python 发送HTML格式的邮件

以下代码是可以发送HTML格式的邮件

 

import smtplib
from email.mime.text import MIMEText

_user = "yy@qq.com"
_pwd = "授权码"
# _to = "ft_clover@163.com"
_recer=["aa@qq.com","bb@163.com",]

mess = """
<p> python 邮件发送测试</p>
<p> <a  href="http://news.baidu.com" target="_blank" class ="mnav c-font-normal c-color-t">这是一个链接-百度新闻</a></p>
"""
msg=MIMEText(mess,'html','utf-8')
msg["Subject"] = " don't panic"
msg["From"] = _user
msg["To"] = ",".join(_recer)#区别与给一个人发,指定某个人用 msg["To"] = _to 多个人用.join

try:
    s=smtplib.SMTP_SSL("smtp.qq.com",465)
    s.login(_user,_pwd)
    s.sendmail(_user,_recer,msg.as_string())
    s.quit()
    print("Success!")
except smtplib.SMTPException as e:
    print("Failed,%s"%e)

 

posted @ 2021-11-17 17:42  eosclover  Views(396)  Comments(0Edit  收藏  举报