本例使用 QQ郵箱測試,需要打開 QQ郵箱的 smtp協議,獲取授權碼
代碼內容如下:
#!/usr/bin/env python# _*_ coding:utf-8 _*___author__ = 'junxi'import smtplibfrom email.mime.text import MIMEText# 文本模式# msg = MIMEText('send by python...', 'plain', 'utf-8')# html 格式msg = MIMEText('<html><body><h1>Hello</h1>' + '<p>send by <a rel="external nofollow" >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)# xxxxxxxxx 是在QQ郵箱獲取的授權碼, 如果不需要授權的郵箱直接輸入密碼即可server.login("xiaoxinxxxx@qq.com", "xxxxxxxxx")server.sendmail("xiaoxinxxxx@qq.com",["xinleixxxx@126.com"],msg.as_string())server.quit()查看結果:

新聞熱點
疑難解答