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(["走心的狗",'XXX@126.com'])
msg['To'] = formataddr(["Wayne",'XXX@qq.com'])
server = smtplib.SMTP()
server.connect("smtp.126.com")
try:
server.login("XXX@126.com", "<126邮箱授权码作为密码登录>")
except:
print("login failed")
server.sendmail('XXX@126.com', ['XXX@qq.com'], msg.as_string())
server.quit()