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
Email which is not a valid class here.✗ Incorrect
The Mail class is imported from flask_mail to send emails.
2fill in blank
mediumComplete the code to create a new email message object.
Flask
msg = [1](subject='Hello', sender='from@example.com', recipients=['to@example.com'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
Mail instead of Message to create the message.Trying to use
Email which is not defined.✗ Incorrect
The Message class creates an email message object.
3fill in blank
hardFix the error in attaching a file to the email message.
Flask
with open('document.pdf', 'rb') as f: msg.attach('document.pdf', [1], f.read())
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
text/plain or application/text for PDF files.Using an image MIME type for a PDF attachment.
✗ Incorrect
The MIME type for PDF files is application/pdf.
4fill in blank
hardFill both blanks to configure Flask-Mail with SMTP server and port.
Flask
app.config['MAIL_SERVER'] = '[1]' app.config['MAIL_PORT'] = [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong SMTP server address.
Using port 465 which is for SSL, not TLS.
✗ Incorrect
Gmail SMTP server is smtp.gmail.com and port 587 is used for TLS.
5fill in blank
hardFill all three blanks to send an email with an attachment using Flask-Mail.
Flask
msg = Message('Report', sender='from@example.com', recipients=['to@example.com']) with open('report.csv', 'rb') as f: msg.attach('[1]', '[2]', f.read()) mail.[3](msg)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong MIME type for CSV files.
Using
send_message which is not a Flask-Mail method.✗ Incorrect
The attachment filename is report.csv, MIME type is text/csv, and the method to send is send.