AttributeError: 'NoneType' object has no attribute 'app' when trying to send mail in Flask [duplicate]
When I invoke with app.app_context():
, I have solved my problem.
def send_email(to, subject, template, **kwargs): msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + subject, sender=app.config['FLASKY_MAIL_SENDER'], recipients=[to]) with app.app_context(): msg.body = render_template(template + '.txt', **kwargs) msg.html = render_template(template + '.html', **kwargs) mail.send(msg)