为什么我收到此错误smtplib.SMTPAuthenticationError

问题描述

这是我面临的错误。我为此使用了应用程序密码(甚至尝试过安全性较低的应用程序),但是它无法正常工作。早些时候它运行良好,但是由于2-3天,它给出了此错误。我想使用smtp代替aouth,所以请您帮帮我。

File "/app/.heroku/python/lib/python3.6/smtplib.py",line 721,in login

2020-09-14T14:38:55.046367+00:00 app[web.1]:     initial_response_ok=initial_response_ok)

2020-09-14T14:38:55.046367+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.6/smtplib.py",line 642,in auth

2020-09-14T14:38:55.046367+00:00 app[web.1]:     raise SMTPAuthenticationError(code,resp)

2020-09-14T14:38:55.046374+00:00 app[web.1]: smtplib.SMTPAuthenticationError: (534,b'5.7.9 Application-specific password required. Learn more at\n5.7.9  https://support.google.com/mail/?p=InvalidSecondFactor n11sm13983956qkk.105 - gsmtp'

这是代码

token = user.get_reset_token()
    message = MIMEMultipart("alternative")
    message["Subject"] = "Password Reset"
    message["From"] = "Test <Config.MAIL_USERNAME>"
    message["To"] = user.email

    # Create the plain-text and HTML version of your message
    text = """\
        Please ignore if you have not requested Password Reset.
    """
    html = u"""\
    <html>
    <body>
        <p>Hi """+str(user.username)+""",</p>
        <p>You requested to reset the password for your account with the e-mail address <mark style = "background: aqua; color: green;">"""+str(user.email)+"""</mark>.<br>Please click this link to reset your password.</p>
        <a href = '"""+str(url_for('users.request_token',token = token,_external = True))+"""'><h3>PASSWORD RESET</h3></a>
        <br>
        <p>Here,is the link in case Password Reset above is not working</p><br>
        <u>"""+str(url_for('users.request_token',_external = True))+"""</u><br><br>
        <p>Thanks,<br><br> Our Team</p>

    </body>
    </html>
    """

    # Turn these into plain/html MIMEText objects
    part1 = MIMEText(text,"plain")
    part2 = MIMEText(html,"html")

    # Add HTML/plain-text parts to MIMEMultipart message
    # The email client will try to render the last part first
    message.attach(part1)
    message.attach(part2)

    # Create secure connection with server and send email
    try:
        context = ssl.create_default_context()
        with smtplib.SMTP_SSL("smtp.gmail.com",465,context=context) as server:
            server.login(Config.MAIL_USERNAME,Config.MAIL_PASSWORD)
            server.sendmail(
                Config.MAIL_USERNAME,user.email,message.as_string()
            )
        flash("Mail Sent!",'success')
    except:
        flash("Mail is not sent Sent! Please check your internet connection.",'info')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)