Note that there are some explanatory texts on larger screens.

plurals
  1. POPython SMTP attachment, not in the body
    primarykey
    data
    text
    <p>I've written with help a script that dumps my iptable logs to a csv. That filename is specified elsewhere as csvout. When using the below code though in my larger script two issues occur</p> <p>First - My mail client (evolution) seems to have issues with the mail (date/time column has a ? in it)</p> <p>Second - The details from the csvout file are sent in the body of the mail (as shown at the bottom) not as an attachment. How can I have the file as an attachment please?</p> <p>Thank you</p> <pre><code># 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() </code></pre> <p>Mail below</p> <pre><code>Return-path: &lt;iptables@wopr&gt; 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 &lt;iptables@wopr&gt;) 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: &lt;1331644805.28329.9.camel@wopr&gt; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload