Using Flask-Mail asynchronously results in “RuntimeError: working outside of application context”

后端 未结 1 448
[愿得一人]
[愿得一人] 2021-01-13 10:35

I am trying to send some mail asynchronously (based on the code in The Flask Mega-Tutorial, Part XI: Email Support). However, I get the following error about working outsid

相关标签:
1条回答
  • 2021-01-13 10:56

    The code should run in an app context. Add with app.app_context():

     @async
     def send_async_email(msg):
        with app.app_context():
           mail.send(msg)
    
    0 讨论(0)
提交回复
热议问题