使用 Django 和 ReportLab 生成 PDF 并将它们附加到电子邮件的最佳方法是什么?
我正在使用 SimpleDocTemplate 并且可以将生成的 PDF 附加到我的 HttpResponse - 这很好,但我无法找出如何将相同的附件准确地添加到电子邮件中:
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=invoice.pdf'
doc = SimpleDocTemplate(response, pagesize=letter)
Document = []
...通过将表格附加到文档来制作我的pdf...
doc.build(Document)
email = EmailMessage('Hello', 'Body', 'from@from.com', ['to@to.com'])
email.attach('invoice.pdf', ???, 'application/pdf')
email.send()
我只是不确定如何将我的 pdfdocument 翻译为 blob,以便 email.attach 可以接受它并且 email.send 可以发送它。
有任何想法吗?