python HTML形式でメールを送信

2203 ワード

qq邮箱:设定->口座を见つけて画像の所smtpを开いて第三者を通じてメールを送るのはすべてPOP 3/IMAP/STMTP/Exchange/CArdDAV/CAldDAVサービスを开く必要がありますhttp://service.mail.qq.com/cgi-bin/help?subtype=1&no=167&id=28python HTML格式发送邮件_第1张图片以下はコードです.
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header

msg_from = '**********@qq.com'  #      
passwd = 'mizfilyvxaxajgfe'  #            
msg_to = '**************@sina.cn'  #      

 #           
message = MIMEMultipart()
message['From'] = Header("   ", 'utf-8')
message['To'] = Header("     ", 'utf-8')
subject = 'Python SMTP     ' #     
 #subject = unicode(subject)#       
message['Subject'] = Header(subject, 'utf-8')
'''
mail_msg = """

...

""" message.attach(MIMEText(mail_msg, 'html', 'utf-8')) html plain html ''' # message.attach(MIMEText(' ……', 'plain', 'utf-8')) # 1, test.txt att1 = MIMEText(open('test.txt', 'rb').read(), 'base64', 'utf-8') att1["Content-Type"] = 'application/octet-stream' # filename , , att1["Content-Disposition"] = 'attachment; filename="demo.txt"' message.attach(att1) try: smtpObj = smtplib.SMTP_SSL("smtp.qq.com", 465) # qq smtp smtpObj.login(msg_from, passwd) smtpObj.sendmail(msg_from, msg_to, message.as_string()) print " " except smtplib.SMTPException: print "Error: "

最後に私の文章があなたを助けてくれたら、手を動かして私のために「いいね」をつけてください.問題があって、伝言を残してください、私は退屈な氷の石です
交流の転載を歓迎します