0
0
Flaskframework~10 mins

Email with attachments 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'
AMessage
BMail
CEmail
DAttachment
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Message instead of Mail.
Using Email which is not a valid class here.
2fill in blank
medium

Complete 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'
AMessage
BEmail
CMail
DAttachment
Attempts:
3 left
💡 Hint
Common Mistakes
Using Mail instead of Message to create the message.
Trying to use Email which is not defined.
3fill in blank
hard

Fix 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'
A'image/png'
B'application/text'
C'application/pdf'
D'text/plain'
Attempts:
3 left
💡 Hint
Common Mistakes
Using text/plain or application/text for PDF files.
Using an image MIME type for a PDF attachment.
4fill in blank
hard

Fill 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'
Asmtp.gmail.com
Bsmtp.mailtrap.io
C587
D465
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong SMTP server address.
Using port 465 which is for SSL, not TLS.
5fill in blank
hard

Fill 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'
Areport.csv
Btext/csv
Csend
Dsend_message
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong MIME type for CSV files.
Using send_message which is not a Flask-Mail method.