Sto usando MIMEText per creare una e-mail da zero in Python 3.2 e ho problemi a creare messaggi con caratteri non ascii nell'oggetto.Codifica delle intestazioni in MIMEText
Per esempio
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()
L'ultima riga mi dà l'errore
UnicodeEncodeError: 'ascii' codec can't encode character '\xbb' in position 0: ordinal not in range(128)
Come faccio a dire MIMEText che il soggetto non è ASCII? subject.encode('utf-8')
non aiuta affatto e comunque ho visto persone che usano stringhe unicode senza problemi in altre risposte (vedi ad esempio Python - How to send utf-8 e-mail?)
Modifica: Vorrei aggiungere che lo stesso codice non dà qualsiasi errore in Python 2.7 (pensato che non significa che il risultato sia corretto).
Apprezzo che stiate cercando di aiutare, ma l'inglese è richiesto su Stack Overflow. Si prega di tradurre questa risposta in inglese. – mhlester