What's the best way to use Django and ReportLab to generate PDFs and attach them to an email message?
I'm using a SimpleDocTemplate and can attach the generated PDF to my HttpResponse - which is great, but I'm having trouble finding out how to exactly add that same attachment to an email:
# 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 = []
... make my pdf by appending tables to the Document...
doc.build(Document)
email = EmailMessage('Hello', 'Body', '[email protected]', ['[email protected]'])
email.attach('invoice.pdf', ???, 'application/pdf')
email.send()
I'm just not sure how to translate my pdfdocument as a blob so that email.attach can accept it and email.send can send it.
Any ideas?