Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://docs.python.org/dev/library/zipfile.html" rel="noreferrer">zipfile</a> module to compress the file using the zip standard, the <a href="http://docs.python.org/dev/library/email.html" rel="noreferrer">email</a> module to create the email with the attachment, and the <a href="http://docs.python.org/dev/library/smtplib.html" rel="noreferrer">smtplib</a> module to send it - all using only the standard library.</p> <h1>Python - Batteries Included</h1> <p>If you don't feel like programming and would rather ask a question on stackoverflow.org instead, or (as suggested in the comments) left off the <code>homework</code> tag, well, here it is:</p> <pre><code>import smtplib import zipfile import tempfile from email import encoders from email.message import Message from email.mime.base import MIMEBase from email.mime.multipart import MIMEMultipart def send_file_zipped(the_file, recipients, sender='you@you.com'): zf = tempfile.TemporaryFile(prefix='mail', suffix='.zip') zip = zipfile.ZipFile(zf, 'w') zip.write(the_file) zip.close() zf.seek(0) # Create the message themsg = MIMEMultipart() themsg['Subject'] = 'File %s' % the_file themsg['To'] = ', '.join(recipients) themsg['From'] = sender themsg.preamble = 'I am not using a MIME-aware mail reader.\n' msg = MIMEBase('application', 'zip') msg.set_payload(zf.read()) encoders.encode_base64(msg) msg.add_header('Content-Disposition', 'attachment', filename=the_file + '.zip') themsg.attach(msg) themsg = themsg.as_string() # send the message smtp = smtplib.SMTP() smtp.connect() smtp.sendmail(sender, recipients, themsg) smtp.close() </code></pre> <p>With this function, you can just do:</p> <pre><code>send_file_zipped('result.txt', ['me@me.org']) </code></pre> <p>You're welcome.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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