2

我如何更改可执行二进制文件的真实文件扩展名以通过 gmail smtp 协议(全部在 python 中)发送该文件。

示例:“二进制”到“binary.jpg”

我会试试这个:

导入 gzip、shutil
src = open('3c7983cb70e9630cc4ee2fe3e1fb16c2', 'rb')
dest = gzip.open('3c7983cb70e9630cc4ee2fe3e1fb16c2.gz.jpg', 'wb')
shutil.copyfileobj(src, dest)

但是当我尝试通过 gmail smtp 发送它时发生了这种情况:

smtplib.SMTPDataError: (552, '5.7.0 我们的系统在您的邮件中检测到非法附件。请\n5.7.0 访问 http://mail.google.com/support/bin/answer.py?answer=6590 到\ n5.7.0 查看我们的附件指南。n18s​​m433437wbh.23')

提前致谢。

4

1 回答 1

5

根据 Google 的政策,二进制文件是被禁止的。

Gmail won't accept these types of files even if they are sent in a zipped
(.zip, .tar, .tgz, .taz, .z, .gz) format. If this type of message is sent to 
your Gmail address, it is bounced back to the sender automatically. 

因此,Google 正在解压缩您的文件,并且很可能会检查文件标题以确定文件类型(不依赖于提供的扩展名。要解决此问题,您可以尝试将其上传为受密码保护的 ZIP 文件,因为 google 无法假设他们允许,将其打开以扫描内容。另一种选择是在发送文件之前对其进行加密,甚至可能非常简单的 XOR 加密也足以通过过滤。然后您需要在检索到文件时解密文件。

于 2011-06-28T21:37:44.570 回答