我已经帮助编写了一个将iptable日志转储到csv的脚本。该文件名在别处指定为csvout。使用下面的代码虽然在我的大脚本中出现了两个问题
首先 - 我的邮件客户端(进化)似乎有邮件问题(日期/时间栏中有一个?)
第二 - csvout文件中的详细信息将在邮件正文中发送(如底部所示),而不是附件。如何将文件作为附件?
谢谢
# Email the file now...
Mail_subj = 'IPTABLES log for '+str(now)
# Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = Mail_subj
sender = 'iptables@wopr'
recp = 'ben@wopr'
msg['From'] = sender
msg['To'] = recp
# Grab todays iptables log file
fp = open(csvout, 'rb')
text = MIMEText(fp.read())
fp.close()
msg.attach(text)
# Send the email
s = smtplib.SMTP('localhost')
s.sendmail(sender, recp, msg.as_string())
s.quit()
下面的邮件
Return-path: <iptables@wopr>
Envelope-to: ben@wopr
Delivery-date: Tue, 13 Mar 2012 13:19:53 +0000
Received: from localhost ([127.0.0.1] helo=[10.100.1.10]) by wopr with
esmtp (Exim 4.76) (envelope-from <iptables@wopr>) id 1S7Rdo-0007mN-TJ for
ben@wopr; Tue, 13 Mar 2012 13:19:52 +0000
Content-Type: multipart/mixed; boundary="===============1365808476=="
MIME-Version: 1.0
Subject: IPTABLES log for 13_03_2012
From: iptables@wopr
To: ben@wopr
X-Evolution-Source: mbox:/var/spool/mail/ben
Date: Tue, 13 Mar 2012 13:20:05 +0000
Message-ID: <1331644805.28329.9.camel@wopr>
X-Evolution-Source: local
--===============1365808476==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Time,MAC,Source_IP,Destination_IP,Protocol,Source_Port,Destination_Port
Mar 12 11:56:28,6c:f0:49:02:3f:d9:00:30:18:ac:a7:22:08:00,10.100.1.1,10.100.1.10,UDP,53,54236
Mar 12 11:56:28,00:00:00:00:00:00:00:00:00:00:00:00:08:00,127.0.0.1,127.0.0.1,UDP,42693,323