mail - Python通过SMTP发送邮件总是验证失败。
天蓬老师
天蓬老师 2017-04-17 16:04:02
[Python讨论组]

以下是我的代码及返回信息,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')

拜托大家帮忙解决下我的问题!!!

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(4)
黄舟

亲,我刚刚试了下,在终端里设置密码时,需要的不是个人密码,而是网易的授权码.
短信里都说了,都没有仔细看....

PHP中文网

你好,为什么我发送出去的邮件的正文是空的?

PHP中文网

谢谢 韦轩 的回答,差点把这个问题给忘了,当初一直出错是因为多年前就把qq smtp服务打开了,不知道后来qq跟163一样开启smtp服务也要设置独立密码。当关闭smtp服务再重新开启并设置密码就没问题了。

PHP中文网

要用客户端授权码代替密码

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号