I am expecting the following code to send an UTF-8 encoded mail.
import email.parser
import smtplib
msg_str = """From: A <a@example.org>
To: B <b@example.org>
Content-Type: text/plain; charset="UTF-8"
Testing UTF-8: – ä."""
msg = email.parser.Parser().parsestr(msg_str)
smtplib.SMTP('localhost').send_message(msg)
However, I am getting this error.
UnicodeEncodeError: 'ascii' codec can't encode character 'u2013' in position 15: ordinal not in range(128)
What is failing here is the flatten call to email.generator.BytesGenerator in pythons smtplib. Shouldn't the email parser fail in the first place if the msg object can't be converted to bytes?
