前言
由于近期在整理发送网络邮件,在使用Python3的email模块发送携带中文附件是,发现Outlook接收到的邮件是乱码,并且后缀变成了.dat,通过网上搜索找到了解决方式,解决方式如下:
解决办法
# 先导入email模块的haeder
from email.header import Header
# 然后在设置附件头的filename处调用Header方法进行编码设置
# 如下:
add_header('Content-Disposition', 'attachment', filename=Header("测试文件.doc", 'utf-8').encode())
参考:https://www.zhihu.com/question/263926241