Django Post Office - html_content KO with attachment

122 views
Skip to first unread message

06us...@gmail.com

unread,
Jan 11, 2016, 3:08:10 PM1/11/16
to Django users
I am using Django 1.8.7 and Django-post-office to send mails with attachment (for instance, one pdf file "test.pdf").

1) Strangely when a mail is sent with an attachment and an HTML_CONTENT (eg "Hello World"), the mail is empty, except the file which is correctly attached. This HTML_CONTENT does not contain html syntax (for testing purpose, such as <strong> </strong>), to keep it very simple.

2) When the mail is sent with same attachment and a (simple) CONTENT (eg "Hello World"), the mail is correctly rendered, with the file correctly attached

3) when the mail is sent with no attachment and an HTML_CONTENT (eg "Hello World"), the mail is correctly rendered (ie, mail is not empty).

So pb is that it is not possible to send mails with attachements and html_content : mail is empty (but file is correctly attached).

Has someone already encountered this behaviour with django-post-office ? Thks.

Артём Мальцев

unread,
Jun 2, 2017, 7:17:53 AM6/2/17
to Django users
I has encountered this behaviour with django-post-office now. And I find one workaround: use both arguments message and html_message in mail.send() method. For example:

msg = render_to_string('path/to/template/', {'some_data': 'some_data'})
pdf
= render_to_pdf(form.pdf_template, email_data)
attachments
= {'Message.pdf': ContentFile(pdf)}
mail
.send(user_email, me, subject=subject, message=msg, html_message=msg, attachments=attachments, headers=headers)


It works for me.
Reply all
Reply to author
Forward
0 new messages