It seems that, in python3, a Header
object is needed to encode a Subject
as utf-8:
# -*- coding: utf-8 -*-
from email.mime.text import MIMEText
from email.header import Header
s = 'a??o'
m = MIMEText(s, 'plain', 'utf-8')
m['Subject'] = Header(s, 'utf-8')
print(repr(m.as_string()))
Output:
'Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Subject: =?utf-8?b?YcOnw6Nv?=
YcOnw6Nv
So the original script would become:
servidor = smtplib.SMTP()
servidor.connect(HOST, PORT)
servidor.login(user, usenha)
assunto = str(self.lineEdit.text())
para = str(globe_email)
texto = str(self.textEdit.toPlainText())
corpo = MIMEText(texto, 'plain', 'utf-8')
corpo['From'] = user
corpo['To'] = para
corpo['Subject'] = Header(assunto, 'utf-8')
servidor.sendmail(user, [para], corpo.as_string())
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…