Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask-Mail extension.
Flask
from flask_mail import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Message instead of Mail
Using wrong class name like FlaskMail
✗ Incorrect
The Flask-Mail extension is imported using Mail.
2fill in blank
mediumComplete the code to create a Flask-Mail instance with the Flask app.
Flask
mail = [1](app) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Message instead of Mail to create instance
Using wrong class name like FlaskMail
✗ Incorrect
You create a Mail instance by passing the Flask app to Mail(app).
3fill in blank
hardFix the error in the code to create an email message with subject and recipients.
Flask
msg = Message(subject='Hello', recipients=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string instead of a list
Using a set or dictionary instead of a list
✗ Incorrect
The recipients argument must be a list of email addresses, so use ['user@example.com'].
4fill in blank
hardFill both blanks to set the email body and send the message.
Flask
msg.body = [1] mail.[2](msg)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sendmail instead of send
Setting body to a variable instead of a string
✗ Incorrect
The email body is set as a string, and the message is sent using mail.send(msg).
5fill in blank
hardFill all three blanks to configure Flask-Mail settings for SMTP server.
Flask
app.config['MAIL_SERVER'] = [1] app.config['MAIL_PORT'] = [2] app.config['MAIL_USE_TLS'] = [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong port number
Setting MAIL_USE_TLS to False when TLS is needed
✗ Incorrect
Use Gmail SMTP server 'smtp.gmail.com', port 587, and enable TLS with True.