0
0
Flaskframework~10 mins

Async email sending in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flask-Mail extension.

Flask
from flask_mail import [1]
Drag options to blanks, or click blank then click option'
AMail
BEmail
CMessage
DFlaskMail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Email' instead of 'Mail' will cause import errors.
Confusing 'Message' which is for email content, not the extension itself.
2fill in blank
medium

Complete the code to create a new email message with Flask-Mail.

Flask
msg = Message(subject='Hello', sender='from@example.com', recipients=['to@example.com'], [1]='This is a test email.')
Drag options to blanks, or click blank then click option'
Acontent
Bmessage
Ctext
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'content' or 'text' will cause errors because they are not valid parameters.
Confusing 'message' with the object name instead of a parameter.
3fill in blank
hard

Fix the error in the async email sending function by completing the code.

Flask
def send_async_email(app, msg):
    with app.[1]():
        mail.send(msg)
Drag options to blanks, or click blank then click option'
Acontext
Bsession
Capp_context
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'context' alone will cause an AttributeError.
Using 'session' or 'request' will not provide the needed app context.
4fill in blank
hard

Fill both blanks to start a new thread for sending email asynchronously.

Flask
from threading import [1]

thread = [2](target=send_async_email, args=(app, msg))
thread.start()
Drag options to blanks, or click blank then click option'
AThread
BProcess
CThreading
DTimer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Process' will run in a separate process, which is heavier than a thread.
Using 'Threading' is the module name, not the class.
Using 'Timer' is for delayed execution, not general threading.
5fill in blank
hard

Fill all three blanks to define and call the async email sending function properly.

Flask
def send_email(app, msg):
    [1] = Thread(target=[2], args=(app, msg))
    [3].start()
Drag options to blanks, or click blank then click option'
Athread
Bsend_async_email
Dmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mail' instead of the thread variable will cause a NameError.
Confusing the target function name with the thread variable.