To attach files to emails sent by django, you need to create an instance EmailMessageand attach the file with .attach().
For example, if you have CSV content in csv_data:
email = EmailMessage('Subject', 'email body', 'from@mail.com', ['to@mail.com'])
email.attach('name.csv', csv_data, 'text/csv')
email.send()
Or, if the CSV data is in a file, you can use:
email.attach_file('/full/path/to/file.csv')
For more information about sending emails, see the docs .
source
share