Niks Jain
Niks Jain

Reputation: 1647

Email attach multiple .CSV in zip file: google app engine python

How do i attach .zip containing multiple .csv file. ex. text_1.csv, text_2.csv

Remember, These csv files constructed from the data in the datastore.

message = mail.EmailMessage()

message.attachments = .... #??
message.send()

Upvotes: 0

Views: 434

Answers (1)

namit
namit

Reputation: 6957

do you want this???

import zipfile, StringIO
o=StringIO.StringIO()
file = zipfile.ZipFile(file=o,compression=zipfile.ZIP_DEFLATED,mode="w")
.. . ## add your csv files here
file.close()
o.seek(0)
self.response.headers['Content-Type'] ='application/zip'
self.response.headers['Content-Disposition'] = 'attachment; filename="your_csvs.zip"'
self.response.out.write(o.getvalue())

for more info visit: http://www.tareandshare.com/2008/09/28/Zip-Google-App-Engine-GAE/

Upvotes: 1

Related Questions