A. The recipients parameter should be a list, not a string
B. The sender email is missing '@' symbol
C. The Message subject must be passed as a keyword argument
D. mail.send() requires two arguments
Solution
Step 1: Check recipients parameter type
The recipients argument must be a list of email addresses, but here it is a string.
Step 2: Validate other parameters
The sender email is valid, subject can be positional, and mail.send() takes one argument (the Message object).
Final Answer:
The recipients parameter should be a list, not a string -> Option A
Quick Check:
Recipients must be list = The recipients parameter should be a list, not a string [OK]
Hint: Recipients must always be a list, even for one email [OK]
Common Mistakes:
Passing recipients as a string
Misplacing subject argument
Expecting mail.send() to take multiple arguments
5. You want to send an email with Flask-Mail only if the recipient list is not empty and the body text is not empty. Which code snippet correctly implements this check before sending?
hard
A. msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg)
B. if recipients or body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg)
C. if recipients and body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg)
D. if not recipients and not body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg)
Solution
Step 1: Understand the condition logic
We want to send email only if both recipients and body are not empty, so use if recipients and body:.
Step 2: Analyze each option
if recipients and body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg) uses correct and condition. if recipients or body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg) uses or which sends email if either is present. if not recipients and not body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg) sends email if both are empty (wrong). msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg) sends email unconditionally.
Final Answer:
if recipients and body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg) -> Option C
Quick Check:
Send only if both present = if recipients and body:
msg = Message(subject='Hi', sender='me@example.com', recipients=recipients, body=body)
mail.send(msg) [OK]
Hint: Use 'and' to check both recipients and body before sending [OK]
Common Mistakes:
Using 'or' instead of 'and' for condition
Sending email without any checks
Checking for empty strings incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.