网上有的教程过期了,这个可以正常发送
首先要开启:发送邮件的邮箱未开启客户端授权码
详见:https://blog.csdn.net/hughnes/article/details/52070878
from email.mime.text import MIMEText
from email.header import Header
import smtplib
sender='###' #发送人的邮箱
sender_pass='***' #发送人的邮箱密码
host='smtp.163.com' #开启的163邮箱的smtp
recivers=['2727328499@qq.com'] #接受者的邮箱
def mail():
message=MIMEText('python 邮件发送','plain','utf-8')#第一个参数为内容,第二个参数为文本格式,第三个为编码
message['From']='{}'.format(sender) #发送者
message['To']=','.join(recivers) #接受者
message['Subject']='邮件测试' #主题
try:
smtpobj=smtplib.SMTP_SSL(host,465)#启用ssl发信,端口为465
smtpobj.login(sender,sender_pass) #登录
smtpobj.sendmail(sender,recivers,message.as_string())
print('sucess')
smtpobj.quit()
except:
print('error')
mail()