python中,使用MIMEApplication封装邮件附件,Outlook为什么无法收到邮件附件?,,在python中使用MI


在python中使用MIMEAppliction封装附件,outlook收到此邮件时无附件。

使用MIMEBase封装附件,outlook可以收到附件。

其他客户端、网页端均正常显示,就想搞明白为什么,以后要如何取舍,在网上看到的办法都是使用MIMEApplication,对不明确的附件类型的附件进行统一包装。

两段代码如下,请教为什么?

file_mail = MIMEApplication(open(fileurl,'rb').read())  file_mail.add_header('Content-Disposition', 'attachment',filename=filename.decode('utf-8').encode('gb2312'))  msg.attach(file_mail)part = MIMEBase('application', 'octet-stream') #'octet-stream': binary data part.set_payload(open(file, 'rb').read())encoders.encode_base64(part)part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file)) msg.attach(part)

编橙之家文章,

评论关闭