Python发送邮件报错:
smtp_server.login(self.sender, self.password) # 登录
File "C:\Python36\lib\smtplib.py", line 697, in login
"SMTP AUTH extension not supported by server.")
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.
要在login之前,加入如下两行代码:
server.ehlo() # 向邮箱发送SMTP 'ehlo' 命令
server.starttls()
# 详细代码
email_host="smtp.xxx.xxx.cn"
smtp = smtplib.SMTP(email_host, port_no)
try:
smtp.connect(email_host, port_no)
smtp.ehlo()
smtp.starttls()
smtp.login(user, password)
smtp.sendmail(sender, to_list+cc_list, msg.as_string())
except:
print("email login failed")