生成excel表格可以用pyExcelerator模块
类似
from pyExcelerator import *
wb = Workbook()
ws = wb.add_sheet('Sheet1')
ws.write(0,0,'host')
ws.write(0,1,'asker')
ws.write(0,2,'head')
ws.write(0,3,'main')
ws.write(0,4,'time')
发送邮件可以用email模块,需要加附件
类似
from email.mime.text import MIMEText
from email.MIMEMultipart import MIMEMultipart
import email.MIMEText
import email.MIMEBase
sender = '
[email protected]'#发件人地址
receiver = '
[email protected]'#收件人地址
smtpserver = 'smtp.qq.com'#邮件服务器
username = '307212178'#用户名
password = 'aaaaaa111111'#密码
smtp = smtplib.SMTP()
def send_email(msg,file_name):
msgRoot = MIMEMultipart()
msgRoot['Subject'] = 'DO not see it!!!!!'#邮件标题,这里我把标题设成了你所发的附件名
msgText = MIMEText('%s'%msg,'html','utf-8')#你所发的文字信息将以html形式呈现
msgRoot.attach(msgText)
att = MIMEText(open('%s'%file_name, 'rb').read(), 'base64', 'utf-8')#添加附件
att["Content-Type"] = 'application/octet-stream'
att["Content-Disposition"] = 'attachment; filename="%s"'%file_name
msgRoot.attach(att)
while 1:#持续尝试发送,直到发送成功
try:
smtp.sendmail(sender, receiver, msgRoot.as_string())#发送邮件
break
except:
try:
smtp.connect(smtpserver)#连接至邮件服务器
smtp.login(username, password)#登录邮件服务器
except:
print "failed to login to smtp server"#登录失败
if __name__ == "__main__":
MSG="表格"#要发送的文字
FILE="C:\\Users\1.txt"#要发送的文件
send_email(MSG,FILE)
里面的内容有删减,你可以自己添加删减