Python通过SMTP发送邮件总是验证失败。
以下是我的代码及返回信息,163和qq的都尝试过但都是验证错误,密码什么的我肯定是没有输错的。
代码:
#-*- encoding: utf-8 -*-
import os, sys
import smtplib
from smtplib import SMTP_SSL
from email.header import Header
from email.mime.text import MIMEText
mailInfo = {
"from": "xxx@qq.com",
"to": "yyy@163.com",
"hostname": "smtp.qq.com",
"username": "xxx@qq.com",
"password": "*********",
"mailsubject": "this is test",
"mailtext": "hello, this is send mail test.",
"mailencoding": "utf-8"
}
if __name__ == '__main__':
smtp = SMTP_SSL(mailInfo["hostname"])
smtp.set_debuglevel(1)
smtp.ehlo(mailInfo["hostname"])
smtp.login(mailInfo["username"],mailInfo["password"])
msg = MIMEText(mailInfo["mailtext"],"text",mailInfo["mailencoding"])
msg["Subject"] = Header(mailInfo["mailsubject"],mailInfo["mailencoding"])
msg["from"] = mailInfo["from"]
msg["to"] = mailInfo["to"]
smtp.sendmail(mailInfo["from"], mailInfo["to"], msg.as_string())
smtp.quit()
返回错误:
send: 'ehlo smtp.qq.com\r\n'
reply: '250-smtp.qq.com\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 73400320\r\n'
reply: '250-AUTH LOGIN PLAIN\r\n'
reply: '250-AUTH=LOGIN\r\n'
reply: '250-MAILCOMPRESS\r\n'
reply: '250 8BITMIME\r\n'
reply: retcode (250); Msg: smtp.qq.com
PIPELINING
SIZE 73400320
AUTH LOGIN PLAIN
AUTH=LOGIN
MAILCOMPRESS
8BITMIME
send: 'AUTH PLAIN AGx************************************vZA==\r\n'
reply: '535 Authentication failed\r\n'
reply: retcode (535); Msg: Authentication failed
Traceback (most recent call last):
File "C:\Users\Daniel\Desktop\mail1.py", line 23, in
smtp.login(mailInfo["username"],mailInfo["password"])
File "C:\Python27\lib\smtplib.py", line 622, in login
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, 'Authentication failed')
拜托大家帮忙解决下我的问题!!!
相关阅读:
h5生成器是如何在pc上模拟展示手机效果的?
Android Studio 颜色选择的问题
php在linux后台定时运行的脚本有哪些?
js 寄生组合式继承
字符串连接问题
如何用git管理ios/mac os项目工程
怎样解释用pointer-events: none;解决苹果使用:checked要点两次的问题?
关于React Native
typecho的定时发布是如何实现的?
devicemotion 兼容性
warning: Could not resolve external type c:objc(cs)NSObject
如何使 li 标签中的文本加粗,但是不让其中的任何标签继承其属性
Subversion svn commit 完后目录就等于host 如何设定
怎样测试post请求的ajax的url链接是否正确?
yii2或者php中,关于事件与行为
error_reporting() 设置 PHP 的报错级
java nio的使用
mongo EDITOR 在windows下 设置问题
移动端的分享效果
移动应用该如何保存用户登录状态