初始化代码:
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 "xxxx@qq.com"
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("xxxx@qq.com", "xxxxx@qq.com", "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')
不知道哪里出了问题,到网上搜了一圈,这个配置没错,就是账户验证失败,就很难受。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.