Skip to content Skip to sidebar Skip to footer

UnicodeEncodeError With Attach_file On EmailMessage Django Error

So I get this error when I try to send an email with EmailMessage in Django. UnicodeEncodeError at /checkout/ 'ascii' codec can't encode character u'\u0161' in position 15: The bo

Solution 1:

So after trying and trying I found a solution that worked for me.

t = loader.get_template('orders/invoice_email.html')
c = {
        'order': order,
    }

body = u''.join(t.render(Context(c))).encode('utf-8').strip()
email = EmailMessage(subject, body, from_mail, [to, ])
email.encoding = "utf-8"
email.content_subtype = "html"
email.attach_file(invoice.name, mimetype="application/pdf")
email.send()

I hope this will help if someone has the same problem.


Post a Comment for "UnicodeEncodeError With Attach_file On EmailMessage Django Error"