kambi
kambi

Reputation: 3433

Email encoding using Django

My webapp stores Hebrew text in a Postgres DB and later sends it as an email. I can see that the text is stored well in the DB, but when sent as an email it look like gibberish:

עובד יקר, זהו טסט של ההתר×ות ×”× ×©×œ×—×•×ª בעברית.

I'm using urlllib to unquote the text from the DB

urllib.unquote(text)

and EmailSender to send the email:

EmailSender().send_html(
    "my email subject",
    email_content,
    [email],
    headers=headers,
    fail_silently=True
)

What can be causing that?

Upvotes: 2

Views: 1121

Answers (1)

Jorge Mauro
Jorge Mauro

Reputation: 383

It's probably happening because the source text is in UTF-8, not in ASCII.

You should take a look at Useful utility functions.

There you will find the smart_text() method, which I think will solve your problem by converting your email_content.


You could also use the encode/decode approach.

Read Standard Encodings and try:

email_content.encode("your_encoding").decode("utf-8")

Upvotes: 1

Related Questions