使用 python email smtplib 模塊發送郵件
本例使用 QQ郵箱測試,須要打開 QQ郵箱的 smtp協議,獲取受權碼
代碼內容以下:
__author__ = 'junxi'
import smtplib
from email.mime.text import MIMEText
msg = MIMEText('<html><body><h1>Hello</h1>' + '<p>send by <a href="http://www.xuegod-for.cn/yum">python</a></body></html>', 'html', 'utf-8')
msg['From'] = "xiaoxinxxxx@qq.com"
msg["To"] = "xinleixxxx@126.com"
msg["Subject"] = "python test"
server = smtplib.SMTP_SSL('smtp.qq.com', 465)
server.set_debuglevel(1)
server.login("xiaoxinxxxx@qq.com", "xxxxxxxx")
server.sendmail("xiaoxinxxxx@qq.com",["xinleixxxx@126.com"],msg.as_string())
server.quit()
複製代碼
查看結果: