I need to send nice-looking emails from Python with address headers that contain names - somehow something that never pops up in tutorials.
I'm using email.mime.text.MIMEText() to create the email, but setting msg['To'] = 'á <x@y.cz>'
rather than utf8-encoding only the name part, will utf8-encode the whole header value, which of course fails miserably. How to do this correctly?
I have found a sort-of solution Python email module: form header "From" with some unicode name + email but it feels hard to accept such a hack, since there does seem to be some support for handling this automatically in Python's email package in email.headerregistry which should be used automatically as far as I can see, but it doesn't happen.