2011-03-21 122 views

回答

8

要将文件附加到由django发送的电子邮件,您必须创建一个EmailMessage实例并使用.attach()方法附加该文件。

例如,假设你有csv_data的CSV内容:

email = EmailMessage('Subject', 'email body', '[email protected]', ['[email protected]']) 
email.attach('name.csv', csv_data, 'text/csv') 
email.send() 

或者,如果CSV数据是在一个文件中,你可以使用:

email.attach_file('/full/path/to/file.csv') 

有关发送的更多信息电子邮件,请参阅the docs