猿问

Python 邮件带Excel附件,但是接收到的附件名和后缀名都不对

如图,收到邮件之后,附件标题不是我设置的,而且后缀名变成了bin,应该是xls

代码片段:

file = MIMEText(open(filepath,'rb').read(),'xls','gb2312')        file["Content-Type"] = 'application/octet-stream'
        file["Content-Disposition"] = 'attachment;filename=%s' % filename        #这我也不知道干啥的
        file.add_header('Content-1','%s' % filename)
        msg.attach(file)

也测试了MIMEBase,结果是一样的...


元芳怎么了
浏览 981回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答