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

后端 未结 7 2103

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条回答
  •  萌比男神i
    2020-12-04 21:20

    I think you have to include it in the message:

    import smtplib
    
    message = """From: From Person 
    To: To Person 
    MIME-Version: 1.0
    Content-type: text/html
    Subject: SMTP HTML e-mail test
    
    This is an e-mail message to be sent in HTML format
    
    This is HTML message.
    

    This is headline.

    """ try: smtpObj = smtplib.SMTP('localhost') smtpObj.sendmail(sender, receivers, message) print "Successfully sent email" except SMTPException: print "Error: unable to send email"

    code from: http://www.tutorialspoint.com/python/python_sending_email.htm

提交回复
热议问题