和大伙分享一个使用python发送html格式的email的代码。 我用在我的软件的bug提交中。代码如下。
请将代码中的email和密码替换成您的email和密码。
# -*- coding: cp936 -*-
'''
send email via gmail,support html email
By Jibo He
[email protected]
'''
import smtplib
msg = """From: From 何吉波 <[email protected]>
To: To UESEO <[email protected]>
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
<b>This is HTML message.</b>
<h1>This is headline.</h1>
<h2><a href="http://www.ueseo.org">优异搜索</a></h2>
"""
server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587
server.ehlo()
server.starttls()
server.ehlo()
server.login('[email protected]','[b]XXXXXX[/b][color=red][/color]')#请替换成您的email和密码
server.sendmail('[email protected]','[email protected]',msg)
server.close()