#coding=utf-8 import smtplib from email.mime.text import MIMEText from email.header import Header #发送邮箱 sender = 'xxxx@163.com' #接收邮箱 receiver = 'xxxxx@qq.com' #发送邮件主题 subject = 'python email test' #发送邮箱服务器 smtpserver = 'smtp.163.com' #发送邮箱用户/密码 username = 'xxxxx@163.com' password = 'xxxxxx' msg = MIMEText('<html><h1>你好!</h1></html>','html','utf-8') msg['Subject'] = Header(subject, 'utf-8') smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit()
运行的时候 报错 smtplib.SMTPDataError: (554, 'DT:SPM 163 smtp14
最后加上了这两行代码就行了
#coding=utf-8 import smtplib from email.mime.text import MIMEText from email.header import Header #发送邮箱 sender = 'xxxxx@163.com' #接收邮箱 receiver = 'xxxxxx@qq.com' #发送邮件主题 subject = 'python email test' #发送邮箱服务器 smtpserver = 'smtp.163.com' #发送邮箱用户/密码 username = 'xxxxx@163.com' password = 'xxxxxx' msg = MIMEText('<html><h1>你好!</h1></html>','html','utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = 'xxxxx@163.com' msg['To'] = 'xxxxxx@qq.com smtp = smtplib.SMTP() smtp.connect('smtp.163.com') smtp.login(username, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit()