开发者

Python: send executable binary file over smtp to gmail

开发者 https://www.devze.com 2023-03-15 21:10 出处:网络
how can i change the real file extension of executable binary to send that file through gmail smtp protocol (all in python).

how can i change the real file extension of executable binary to send that file through gmail smtp protocol (all in python).

Example: "binary" to "binary.jpg"

I'll try this:

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

but when I try to send it via gmail smtp happens to this:

smtplib.SMTPDataError: (552, '5.7.0 Our system dete开发者_如何学JAVActed an illegal attachment on your message. Please\n5.7.0 visit http://mail.google.com/support/bin/answer.py?answer=6590 to\n5.7.0 review our attachment guidelines. n18sm433437wbh.23')

Thancks in advance.


According to Google's Policy, binary files are banned.

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. 

So Google is unzipping your file and most likely checking the file headers to determine the file type (not relying on the extension provided. To get around this you could try uploading it as a password protected ZIP file, since google wouldn't be able to crack it open to scan the contents, assuming they allow that. Another option would be to encrypt the file before sending it, possibly even a very simple XOR encryption might be enough to get past the filtering. You would then need to decrypt upon retrieving the file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号