[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 = "961769710@qq.com"
FROM = "15517707935@163.com"
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("""
<table width="600" border="0" cellspacing="0" cellpadding="4">
<tr bgcolor="#CECFAD" height="20" style="font-size:14px">
<td colspan=2>*Website performance data <a href="monitor.domain.com">more>></a></td>
</tr>
<tr bgcolor="#EFEBDE" height="100" style="font-size:13px">
<td>
<img src="cid:io"></td><td>
<img src="cid:key_hit"></td>
</tr>
<tr bgcolor="#EFEBDE" height="100" style="font-size:13px">
<td>
<img src="cid:men"></td><td>
<img src="cid:swap"></td>
</tr>
</table>""","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("15517707935@163.com","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]#
网友评论