如何实现用户自定义的定时任务(第2个答案)

从 Python 通过 SMTP 发送 SMS 始终无法通过身份验证。

问题描述:

以下是我的代码和返回信息。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.comrn'
reply: '250-smtp.qq.comrn'
reply: '250-PIPELININGrn'
reply: '250-SIZE 73400320rn'
reply: '250-AUTH LOGIN PLAINrn'
reply: '250-AUTH=LOGINrn'
reply: '250-MAILCOMPRESSrn'
reply: '250 8BITMIMErn'
reply: retcode (250); Msg: smtp.qq.com
PIPELINING
SIZE 73400320
AUTH LOGIN PLAIN
AUTH=LOGIN
MAILCOMPRESS
8BITMIME
send: 'AUTH PLAIN AGx************************************vZA==rn'
reply: '535 Authentication failedrn'
reply: retcode (535); Msg: Authentication failed
Traceback (most recent call last):
  File "C:UsersDanielDesktopmail1.py", line 23, in 
    smtp.login(mailInfo["username"],mailInfo["password"])
  File "C:Python27libsmtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, 'Authentication failed')

请帮我解决我的问题!!!

第一个答案

亲,很明显是登录认证失败了,一般是没有开启SMTP服务。

我关闭了服务,和你的错误一样。

重新打开服务,就成功了。具体开户可以在美国网站上查到163邮件没有其他smtp服务器,一般是在账户上设置的。

附上我成功的截图和日志

send: 'ehlo [222.212.253.207]rn'
reply: '250-smtp.qq.comrn'
reply: '250-PIPELININGrn'
reply: '250-SIZE 73400320rn'
reply: '250-STARTTLSrn'
reply: '250-AUTH LOGIN PLAINrn'
reply: '250-AUTH=LOGINrn'
reply: '250-MAILCOMPRESSrn'
reply: '250 8BITMIMErn'
reply: retcode (250); Msg: smtp.qq.com
PIPELINING
SIZE 73400320
STARTTLS
AUTH LOGIN PLAIN
AUTH=LOGIN
MAILCOMPRESS
8BITMIME
send: 'AUTH PLAIN ADgwNTM2NjE4MEBxcS5jb20AMjAxNXdvaGVuaGFvPz8=rn'
reply: '235 Authentication successfulrn'
reply: retcode (235); Msg: Authentication successful
send: 'mail FROM: size=128rn'
reply: '250 Okrn'
reply: retcode (250); Msg: Ok
send: 'rcpt TO:rn'
reply: '250 Okrn'
reply: retcode (250); Msg: Ok
send: 'datarn'
reply: '354 End data with .rn'
reply: retcode (354); Msg: End data with .
data: (354, 'End data with .')
send: 'Content-Type: text/plain; charset="utf-8"rnMIME-Version: 1.0rnContent-Transfer-Encoding: base64rnrnaGVsbG8sIHNlbmQgYnkgUHl0aG9uLi4urn.rn'
reply: '250 Ok: queued as rn'
reply: retcode (250); Msg: Ok: queued as
data: (250, 'Ok: queued as')
send: 'quitrn'
reply: '221 Byern'
reply: retcode (221); Msg: Bye

第二个答案:

亲,我刚试过。在终端设置密码时,我需要的不是个人密码,而是网易的授权码。

邮件里都说了,但是我没仔细看。。。

第三个答案:

你好163邮件没有其他smtp服务器,为什么我发的短信正文是空的?

第4个答案:

感谢魏轩的回答,我差点忘了这个问题。报错原因是多年前开通了qqsmtp服务。不知道qq像163一样要设置独立密码才能打开smtp服务。当关闭smtp服务再重新打开并设置密码,就没有问题了。

第5个答案:

用客户端授权码替换密码

下一节:php如何实现用户自定义的定时任务

现在遇到一个问题:用户A登录后台后,设置定时任务每晚9:00执行,用户B登录后台后,设置定时任务每晚8点执行00 早上,用户 C... 如何为用户设计这些功能是 web...

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

悟空资源网 网站程序 如何实现用户自定义的定时任务(第2个答案) https://www.wkzy.net/game/8420.html

常见问题

相关文章

官方客服团队

为您解决烦忧 - 24小时在线 专业服务