python实现图文格式的服务器性能报表邮件(qq)

[root@www smtplib]# cat qq_mail_tupian.py

!/usr/bin/env python

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

HOST = "smtp.163.com"
SUBJECT = "Business performance data report"
TO = "[email protected]"
FROM = "[email protected]"

def addimg(src,imgid):
fp = open(src, 'rb')
msgImage = MIMEImage(fp.read())
fp.close()
msgImage.add_header('Content-ID', imgid)

return msgImage    

msg = MIMEMultipart('related')

msgtext = MIMEText("""











*Website performance data more>>




""","html","utf-8")

msg.attach(msgtext)
msg.attach(addimg("img/bytes_io.png","io"))

msg.attach(addimg("img/myisam_key_hit.png","key_hit"))
msg.attach(addimg("img/os_mem.png","men"))
msg.attach(addimg("img/os_swap.png","swap"))
msg['Subject'] = SUBJECT #subject
msg['From']=FROM
msg['To']=TO
try:
server = smtplib.SMTP() #create
server.connect(HOST,"25") #by connect connect smtp host
server.starttls() #ssl safe
server.login("[email protected]","kptgpcamuyzxodvo") #login
server.sendmail(FROM, TO, msg.as_string()) #send mail
server.quit() #quit smtp connect
print "send yes"
except Exception, e:
print "lose:"+str(e)
[root@www smtplib]#

测试:

[root@www smtplib]# python qq_mail_tupian.py
send yes
[root@www smtplib]#

有图
http://9399369.blog.51cto.com/9389369/1735349

你可能感兴趣的:(python实现图文格式的服务器性能报表邮件(qq))