Skip to content Skip to sidebar Skip to footer

"RuntimeError: Working Outside Of Application Context " With Python Flask App ( Sending Gmail Using Scheduler )

app = Flask(__name__) app.config.update( MAIL_SERVER = 'smtp.gmail.com', MAIL_PORT = 465, MAIL_USE_SSL = True, MAIL_USE_TLS = False, MAIL_USERNAME = '******',

Solution 1:

Your function print_date_time is being executed through a new thread outside the app context and the Mail object need it. You should pass a param with the app object to your function (the decorator route is not necessary). The value of this param is current_app._get_current_object().

I have reimplemented your function print_date_time:

def print_date_time(app):
    with app.app_context():
        Symbol = "PG"
        Symbol = lookup(Symbol)
        msg = mail.send_message(
            'PG',
            sender='*****',
            recipients=['******'],
            body = "PG DROP BELOW 91 buy now"
        )

Post a Comment for ""RuntimeError: Working Outside Of Application Context " With Python Flask App ( Sending Gmail Using Scheduler )"