I'm creating an email using Python's email
package (which is awesome!!).
I found out that it's better to encode the headers that have some weird chars in them (accents, etc), like the subject, using email.Header.
To do so, I'm doing the following, which is quite easy:
Header(value, 'UTF-8').encode()
It works great, but it also encode the fields that doesn't necessary require an encoding, lik
X-Mailer: My Service
that becomes
X-Mailer: =?utf-8?q?My_Service?=
I find it pretty useless in that case.
So my question: Is there a way to encode headers only when it will be useful?
I thought about playing with value.encode/decode()
with a try/except, and call the Header().encode()
function in the except, but I'm hoping there is a cleaner way to do so?