Python email comes with Excel attachments, but the attachment name and suffix name received are incorrect

as shown in the figure, after receiving the email, the attachment title is not set by me, and the suffix name is changed to xls
clipboard.png

.

Code snippet:

file = MIMEText(open(filepath,"rb").read(),"xls","gb2312")
        file["Content-Type"] = "application/octet-stream"
        file["Content-Disposition"] = "attachment;filename=%s" % filename
        -sharp
        file.add_header("Content-1","%s" % filename)
        msg.attach(file)

also tested that the MIMEBase, result is the same.

Jun.17,2021

is the attachment in Chinese? if so, here is a previous code snippet of my own, using make_header

from email.header import  make_header
file_msg = MIMEText(open(file,'rb').read(), 'base64', 'UTF-8')
file_msg["Content-Type"] = 'application/octet-stream;name="%s"'% make_header([(file,'UTF-8')]).encode('UTF-8')
file_msg["Content-Disposition"] = 'attachment;filename= "%s"'% make_header([(file, 'UTF-8')]).encode('UTF-8')
msg.attach(file_msg)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37f50-2b920.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37f50-2b920.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?