126邮箱发送邮件python实现

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了126邮箱发送邮件python实现相关的知识,希望对你有一定的参考价值。

126邮箱发送邮件python实现

from email.mime.text import MIMEText
from email.utils import formataddr
import smtplib

def mail():

    msg = MIMEText(这是一封测试邮件 by python3,plain,utf-8)
    msg[From] = formataddr(["走心的狗",[email protected]])
    msg[To] = formataddr(["Wayne",[email protected]])
    server = smtplib.SMTP()
    server.connect("smtp.126.com")
    try:
        server.login("[email protected]", "<126邮箱授权码作为密码登录>")
    except:
        print("login failed")
    server.sendmail([email protected], [[email protected]], msg.as_string())
    server.quit()

 

以上是关于126邮箱发送邮件python实现的主要内容,如果未能解决你的问题,请参考以下文章