Python: “subject” not shown when sending email using smtplib module

后端 未结 7 2116

I am successfully able to send email using the smtplib module. But when the emial is sent, it does not include the subject in the email sent.

import smtplib
         


        
7条回答
  •  感动是毒
    2020-12-04 21:24

    See the note at the bottom of smtplib's documentation:

    In general, you will want to use the email package’s features to construct an email message, which you can then convert to a string and send via sendmail(); see email: Examples.

    Here's the link to the examples section of email's documentation, which indeed shows the creation of a message with a subject line. https://docs.python.org/3/library/email.examples.html

    It appears that smtplib doesn't support subject addition directly and expects the msg to already be formatted with a subject, etc. That's where the email module comes in.

提交回复
热议问题