msg = Message('qqq',recipients=['email@qq.com'])
msg.body = "order"
msg.html = 'html'
@copy_current_request_context
def send_async_email(msg):
mail.send(msg)
thr = Thread(target = send_async_email, args = [msg])
thr.start()
网上看到的代码是没有加@copy_current_request_context,新版本不加的话会出RuntimeError: working outside of application context的错误。经过测试直接运行程序可以发送,但使用域名访问没有任何反应。经过多方面查找。发现是uwsgi默认不支持子线程。加在配置文件里加上enable-threads = true。这样就可以发送成功了。
flask 异步发送邮件
最新推荐文章于 2024-05-12 17:37:28 发布