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

后端 未结 7 2094

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:37

    You should probably modify your code to something like this:

    from smtplib import SMTP as smtp
    from email.mime.text import MIMEText as text
    
    s = smtp(server)
    
    s.login(, )
    
    m = text(message)
    
    m['Subject'] = 'Hello!'
    m['From'] = 
    m['To'] = 
    
    s.sendmail(, , m.as_string())
    

    Obviously, the <> variables need to be actual string values, or valid variables, I just filled them in as place holders. This works for me when sending messages with subjects.

提交回复
热议问题