Generating zipped or gzipped attachment with email package?

S

skip

I have a script which allows me to generate MIME messages with appropriate
attachments. It's essentially a lightly modified version of the second
example from this page of the email package docs:

http://docs.python.org/library/email-examples.html

I want to modify my script to automatically zip or gzip files which exceed
some size threshold. Doing the zip/gzip dance is no problem. I'm concerned
about how to specify that properly with the email package. For example,
consider a large CSV file. I figure out the MIME type is text/csv. Now
suppose I gzip the file before attaching it. How would this code change to
specify the compression where "path" is now compressed?

if maintype == 'text':
fp = open(path)
# Note: we should handle calculating the charset
msg = MIMEText(fp.read(), _subtype=subtype)
fp.close()

I guess I'm asking if I can have the Content-Type still be text/csv with
some other MIME header indicating the file is compressed. If so, how do I
achieve that when attaching the compressed file to the message?

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top