我正在使用Python模块MimeWriter
构造一封邮件,并使用smtplib发送。构造的邮件内容如下:
file msg.txt:
-----------------------
Content-Type: multipart/mixed;
from: me<me@abc.com>
to: me@abc.com
subject: 主題
Content-Type: text/plain;charset=utf-8
主題
我使用以下代码发送邮件:
import smtplib
s=smtplib.SMTP('smtp.abc.com')
toList = ['me@abc.com']
f=open('msg.txt') #above msg in msg.txt file
msg=f.read()
f.close()
s.sendmail('me@abc.com',toList,msg)
我可以正确获取电子邮件正文,但主题不正确。
subject: some junk characters
主題 <- body is correct.
请建议?是否有办法指定用于主题的解码方式,就像为正文指定的那样。我如何正确地解码主题?