Encoding of headers in MIMEText
问题 I'm using MIMEText to create an email from scratch in Python 3.2, and I have trouble creating messages with non-ascii characters in the subject. For example from email.mime.text import MIMEText body = "Some text" subject = "» My Subject" # first char is non-ascii msg = MIMEText(body,'plain','utf-8') msg['Subject'] = subject # <<< Problem probably here text = msg.as_string() The last line gives me the error UnicodeEncodeError: 'ascii' codec can't encode character '\xbb' in position 0: ordinal