Bird
0
0

What is wrong with this code snippet for sending an email alert?

medium📝 Debug Q7 of 15
Raspberry Pi - Automation and Scheduling
What is wrong with this code snippet for sending an email alert?
import smtplib
sensor_value = 85
if sensor_value > 80:
    smtp = smtplib.SMTP('smtp.gmail.com', 587)
    smtp.sendmail(from_addr, to_addr, message)
    smtp.quit()
AIncorrect SMTP server address
BMissing starttls() call before sending email
CNo condition to check sensor value
Dsmtp.quit() should be called before sendmail()
Step-by-Step Solution
Solution:
  1. Step 1: Review SMTP email sending steps

    For Gmail SMTP on port 587, starttls() must be called to secure the connection before sending email.
  2. Step 2: Check other parts

    Server address is correct, condition exists, quit() is correctly after sendmail().
  3. Final Answer:

    Missing starttls() call before sending email -> Option B
  4. Quick Check:

    Use starttls() before sendmail() with Gmail SMTP [OK]
Quick Trick: Call starttls() before sending email via SMTP [OK]
Common Mistakes:
MISTAKES
  • Skipping starttls()
  • Wrong SMTP server
  • Calling quit() too early

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes