#/usr/bin/env python
#coding=utf-8
#
#from_addr = 'xx@163.com'
#password = 'xxx'
#to_addr = 'xxx@qq.com'
#smtp_server = 'smtp.163.com'
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
HOST = "smtp.163.com"
SUBJECT = u"官网业务服务质量周报"
TO = "xxx@qq.com"
FROM = "xxx@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("<font color=red>官网业务周平均延时图表:<br><img src=\"cid:weekly\" border=\"1\"><br>详细内容见附件。</font>","html","utf-8")
msg.attach(msgtext)
msg.attach(addimg("weekly.png","weekly"))
attach = MIMEApplication(open('曾柏超的简历.doc','rb').read())
attach.add_header('Content-Disposition', 'attachment', filename="曾柏超的简历.doc")
msg.attach(attach)
msg['Subject'] = SUBJECT
msg['From']=FROM
msg['To']=TO
try:
server = smtplib.SMTP()
server.connect(HOST,"25")
server.starttls()
server.login("xxxx@163.com","xxxx")
server.sendmail(FROM, TO, msg.as_string())
server.quit()
print "邮件发送成功!"
except Exception, e:
print "失败:"+str(e)
网友评论