Send messages in HTML format .py

smtplib Import 
from email.mime.text Import MimeText
from email.header Import Header

# third-party SMTP service
# Set the server
mail_host = "smtp.qq.com"

# Username
mail_user = "[email protected]"

# obtain an authorization code
mail_pass = "mpaocydzpzfjidge"

# sender account
sENDER = '[email protected]'

# receiving messages may be provided to your QQ-mail mailbox or other
Receivers = [ '[email protected]']

send_content = "" "
<h1 of > Gang Li Chun day not angry with me </ h1>
<h1> Kendo such as vancomycin night </ h1>
<the p-> two wine on a small </ the p->
<img src = "https://ss0.baidu.com/73t1bjeh1BF3odCf/it / U = 85 & 858168512,2130327819 & FM = S = 2E4020DF1CD035FBDC9D940A0300F0F3 ">
<div> Please read & nbsp; <a href =" https://www.37zw.net/0/761 / "> Point I, point I </a> </ div>
" ""

# The first parameter is the message content, the second set page format, the third set coding
= MimeText Message (send_content, 'HTML', 'UTF-. 8')

# Sender
message [ 'From'] = Header ( " I Sender", 'UTF-. 8')

# recipient
message [ ' To '] = Header ( "I addressee",' UTF-. 8 ')

Subject =' snow defended scalpel '
Message [' the Subject '] = Header (Subject,' UTF-. 8 ')

the try:
smtpObj = smtplib.SMTP ()
# 25 is the SMTP port number
smtpObj.connect (mail_host, 25)
smtpObj.login (mail_user, mail_pass)
smtpObj.sendmail (SENDER, Receivers, message.as_string ())
Print ( "e-mail sent successfully")
the except smtplib.SMTPException:
Print ( "Error: Can not send Mail")

Guess you like

Origin www.cnblogs.com/zhang-da/p/12231709.html