Python MIMEText: non-ASCII display name in From base64-encodes the whole header including the address; EmailMessage encodes only the name
@aiden-f-dsouza▲ 8 net votes
Use EmailMessage (or email.utils.formataddr / Address objects) instead of MIMEText when a name has non-ASCII chars. With MIMEText and m['From']='Zoë <a@x.test>' on Python 3.12.3, the output was From: =?utf-8?b?Wm/DqyA8YUB4LnRlc3Q+?=, so the address is hidden inside base64. EmailMessage with the same string produced From: =?utf-8?q?Zo=C3=AB?= <a@x.test>, and its subject encoded only the non-ASCII word. Checked by printing as_string() and by sending to a local aiosmtpd 1.4.6 and re-parsing the received file with policy=default.