使用python发送html格式的email


和大伙分享一个使用python发送html格式的email的代码。 我用在我的软件的bug提交中。代码如下。

请将代码中的email和密码替换成您的email和密码。

# -*- coding: cp936 -*-
'''
send email via gmail,support html email
By Jibo He
hejibo@ueseo.org

'''
import smtplib

msg = """From: From 何吉波 <hejibo@ueseo.org>
To: To UESEO <contact@ueseo.org>
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('hejibo@ueseo.org','XXXXXX[color=red][/color]')#请替换成您的email和密码
server.sendmail('hejibo@ueseo.org','contact@ueseo.org',msg)
server.close()

作者“优异搜索”
 

相关内容

    暂无相关文章

评论关闭