为什么我会遇到烧瓶邮件问题?

Why am I facing flask-mail issues?

我不知道该怎么办

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

with app.app_context():
    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 587
    app.config['MAIL_DEFAULT_SENDER'] = 'sender'
    app.config['MAIL_USERNAME'] = 'sender'
    app.config['MAIL_PASSWORD'] = '*************'
    app.config['MAIL_USE_TSL'] = True
    mail = Mail(app)
    mail.send_message('Mail sent', sender = 'sender', recipients = ['recipients'], body = 'Mail sent successfully')

它告诉我 smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server 我什至在 gmail 中启用了来自安全性较低的应用程序的电子邮件。为什么它似乎不起作用? 我已尝试查找错误,但尚未找到令人满意的答案。

编辑:我使用 SSL 而不是 TLS 进行加密,它似乎向我显示了一个不同的错误。现在它告诉我 smtplib.SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError 我不知道下一步该做什么。我不知道如何启用 DisplayUnlockCaptcha。 https://accounts.google.com/DisplayUnlockCaptcha 是它的 link。我继续执行 link 所说的,它告诉我“已启用帐户访问权限 请尝试从您的新设备或应用程序再次登录您的 Google 帐户。”我重试了,仍然无法登录。

问题已解决!

您可以尝试多种方法,例如激活 ssl

app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True

You must not enable both tls and ssl together

您需要对您的 Gmail 帐户应用一系列设置,例如禁用 2FADisplay Unlock Captcha

本教程概述了工作步骤。

https://twilio.com/blog/2018/03/send-email-programmatically-with-gmail-python-and-flask.html