#!/usr/bin/python #coding: utf-8 import sys import smtplib from email.mime.text import MIMEText import re,commands def lastline(): global pos while True: pos = pos - 1 try: f.seek(pos, 2) if f.read(1) == ‘\n‘: break except: f.seek(0, 0) return f.readline().strip() return f.readline().strip() def mail_send(text=‘‘,subject=‘未定义主题‘): mail_host = "xxx" mail_user = "xxx" mail_pass = "xxx" mail_list_to = ["xxx","xxx"] mail_from = "xxx" msg = MIMEText(str(text),"html","utf-8") msg[‘Subject‘] = subject msg[‘From‘] = mail_from msg[‘To‘] = ",".join(mail_list_to) try: server = smtplib.SMTP() server.connect(mail_host,"25") server.starttls() server.login(mail_user,mail_pass) server.sendmail(mail_from,mail_list_to,msg.as_string()) server.quit() print "邮件发送成功!" except Exception,e: print "失败:"+str(e) if __name__ == "__main__": process = commands.getoutput(‘xxx‘) flag = re.search(‘xxx‘,process) if flag: f = open(‘xxx‘,‘r‘) pos = 0 log = [] for line in range(1000): log.append(lastline()) log.reserse() text1 = log sub = ‘xxx‘ print text1 f.close() mail_send(text1,sub)
本文出自 “大成” 博客,请务必保留此出处http://liuchw.blog.51cto.com/6858799/1675763
原文地址:http://liuchw.blog.51cto.com/6858799/1675763