Python sends email attachments as excel attachments named Chinese garbled characters

Set the filename of the attachment header and call the Header method to set the encoding

Don't talk nonsense and go directly to the code

from email. Header import Header


excel_name = r'测试.xlsx'
# 防止网页端和MacOS端邮件附件显示乱码
file_excel_name = Header(excel_name, 'utf-8').encode()  

Guess you like

Origin blog.csdn.net/weixin_42131208/article/details/128799506