For effective work on the site, cookies and the processing of personal data are used. By using this site, you agree to the terms of use of the site. More

Quote of day

Maltsev Artem's Personal Site

Imagination is everything. It is the preview of life’s coming attractions.

Albert Einstein

html_content with attachment in django-post_office

July 30, 2017, 6:25 p.m.

I get strange bug with attachment in django-post-office (at least, it's encountered in version 2.0.8 and lower): when the mail is sent, which consist of html-content with attachment (of any format), the mail is come, but without attachment.

I used next package version:

django==1.10.7 (and lower)
django-post-office==2.0.8 (and lower)

In more detail, the behavior of django-post-office of the specified version and the working of the mail.send() method can be described as follows:

  1. When the mail is sent with simple content, using message parameter, and with attachment - it works correctly, i. e. I get mail with attachment.
  2. When the mail is sent with content, which contains html-tags or even plain text without tags, using html_message parameter, and with attachment - it does not work correctly, i. e. I get the empty mail, but file is attached.
  3. When the mail is sent with content, using html_message parameter, but without attachment - it work correctly, i. e. I get the mail formated by html-tags and with attachment.

And I find the workaround of this strange gug: use both arguments message and html_message. 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)

Rate this article

0 from 5 (total 0 ratings)

You can send feedback, suggestions or comments on this article using this form:

Fields marked by star ( * ) is required.

Thank you for yor feedback!

Article Author

The right to use this article on this page

Permission is granted to copy an article with its author and reference to the original without using the parameter rel="nofollow" in tag <a>. Usage:

Article Author: Maltsev Artem
Link to article: <a href=""></a>

More: Terms of site usage

Do you need to develop yourself or do you want to earn money?

Are you looking for good IT services or books? Save your time and look at my compilation of recommendations, which I use every day.
Go to recommendations

Comments: 0

You can leave a comment as an unregistered user. But by registering, you will be able to receive notifications of replies, and also have access to your personal account to view your comments.

To comment in one's own name you should log in or sign up in the usual way or through social networks:


There is no search on this site, so I offer to use usual search engine, for example, Google, adding "vivazzi" after your request.

Try it