初始化代码:
app = create_app()
# mail client
mail = Mail(app)
配置文件:
# flask_mail
MAIL_DEBUG = False
MAIL_SUPPRESS_SEND = False
MAIL_SERVER = 'smtp.qq.com'
MAIL_PORT = 465
MAIL_USE_SSL = True
MAIL_USE_TLS = False
MAIL_USERNAME = os.getenv("MAIL_USERNAME") or "[email protected]"
MAIL_PASSWORD = os.getenv("MAIL_PASSWORD") or "xxxxxxxxxxx" # QQ 邮箱授权码
发送邮件代码:
@celery.task
def send(mail_from, mail_to, subject="", content="", html=""):
try:
msg = Message(
subject=subject,
sender=mail_from,
recipients=[mail_to]
)
msg.body = content
msg.html = html
mail.send(msg)
except Exception as e:
return e.__str__()
return "ok"
send.delay("[email protected]", "[email protected]", "test", "content")
错误信息:
(535, b'Login Fail. Please enter your authorization code to login. More information in
http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256')
不知道哪里出了问题,到网上搜了一圈,这个配置没错,就是账户验证失败,就很难受。

