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

后端 未结 7 2097

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

     import smtplib
    
     # creates SMTP session 
    
    List item
    
     s = smtplib.SMTP('smtp.gmail.com', 587)
    
     # start TLS for security   
     s.starttls()
    
     # Authentication  
     s.login("login mail ID", "password")
    
    
     # message to be sent   
     SUBJECT = "Subject"   
     TEXT = "Message body"
    
     message = 'Subject: {}\n\n{}'.format(SUBJECT, TEXT)
    
     # sending the mail    
     s.sendmail("from", "to", message)
    
     # terminating the session    
     s.quit()
    

提交回复
热议问题