如何发送带有附件的电子邮件? [英] How to send an email with attachment?
本文介绍了如何发送带有附件的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用xlwt我已经创建了一个Excel表格,使用Django我想作为附件发送电子邮件。
Using xlwt I have created an Excel sheet that with Django I would like to email as an attachment.
response = HttpResponse(mimetype='application/ms-excel')
response['Content-Disposition'] = 'attachment; filename='Report.xls'
book = xlwt.Workbook()
sheet = book.add_sheet("Core Listings")
book.save(response)
return response
我正在使用Django EmailMessage
发送电子邮件。
I am using Django EmailMessage
to send out emails.
推荐答案
您应该能够从电子表格数据中创建内存中的MimeBase对象,在attach方法中附加该对象。 attach方法会使用文件三元组或MimeBase对象。有关MimeBase和 pydoc描述。 wordpress.com/2012/01/13/send-emails-using-python/rel =nofollow>一个例子。
You should be able to create a MimeBase object in memory from the spreadsheet data and attach that object in the attach method. The attach method takes the file triplet or a MimeBase object. See pydoc description about MimeBase and an example.
这篇关于如何发送带有附件的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文