Complete the code to import the Flask-Mail extension.
from flask_mail import [1]
The Flask-Mail extension is imported using Mail. This allows you to send emails asynchronously in Flask.
Complete the code to create a new email message with Flask-Mail.
msg = Message(subject='Hello', sender='from@example.com', recipients=['to@example.com'], [1]='This is a test email.')
The Message object uses the body parameter to set the plain text content of the email.
Fix the error in the async email sending function by completing the code.
def send_async_email(app, msg): with app.[1](): mail.send(msg)
To send emails asynchronously in Flask, you need to push the application context using app.app_context() so the mail extension works properly outside the request.
Fill both blanks to start a new thread for sending email asynchronously.
from threading import [1] thread = [2](target=send_async_email, args=(app, msg)) thread.start()
The Thread class from the threading module is used to run functions asynchronously in a separate thread.
Fill all three blanks to define and call the async email sending function properly.
def send_email(app, msg): [1] = Thread(target=[2], args=(app, msg)) [3].start()
We create a thread variable as a Thread object targeting the send_async_email function, then start the thread with thread.start().