I have a requirement to export some data from a table (not all fields + some properties) and send it as an attachment in an email.
I was thinking to create a StringIO object with the CSV contents and upload it to the blobstore and attach the file to the email. But I don’t know how to go from StringIO to uploaded file.
We might be dealing with 100K+ records, could this be a problem?
As documented, the
mail.send_mailfunction takes an argument ‘attachments’, which should be a list of 2-tuples, being the filename and the contents of the file to attach. You can get the contents from a StringIO by calling.get_value()on it.As to size, outgoing emails are limited to 10MB. If your CSV file is bigger than that, then yes, you will run into trouble. If you can, compress it with gzip or zipfile before sending.