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)
Menu