【python】发送电子邮件(QQ邮箱为例)出现错误提示 smtplib.SMTPAuthenticationError: (535, b’Login Fail. 的解决方案 代码示例:
import smtplib
from email.mime.text import MIMEText
msg_from="**********qq.com"
pwd="valrxegpsamlebed"
to="**********qq.com"
subject="这是python发送的"
content="hello world"
msg=MIMEText(content)
msg["Subject"]=subject
msg["From"]=msg_from
msg["To"]=to
try:
ss=smtplib.SMTP_SSL("smtp.qq.com",465)
ss.login(msg_from,pwd)
ss.sendmail(msg_from,to,msg.as_string())
print("发送成功")
except Exception as e:
print("发送失败:",e)
在执行上述代码时出现以下错误提示:
smtplib.SMTPAuthenticationError: (535, b'Login Fail. Please enter your authorization code to login. More information in http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256')
这里以QQ邮箱为例,进入QQ邮箱设置中的账号设置,下划找到以下内容:  可以看到IMPA/SMTP服务是关闭的,将其开启,开启成功后注意保留授权码,再次测试,邮件发送成功。  如果帮到您的话,请点赞、收藏支持一下哦,谢谢您
|