当我通过电子邮件message模块将zip文件夹发送给我自己时,请遇到无效的zip文件错误
首先,我不确定是否要以正确的方式附加此 zip 文件夹。我已经将不同的东西组合在一起,但是我收到一条错误消息,在该消息下面我链接到了代码的底部。
from email.message import EmailMessage
import shutil
message = EmailMessage()
message["From"] = "[email protected]"
message["To"] = "[email protected]"
message["Subject"] = "Testing Zip"
path = "Testing.zip"
with open(path, "rb") as f:
bytes = f.read()
encoded = base64.b64encode(bytes)
message.add_attachment(encoded, maintype='application/zip', subtype='octet-stream', filename="Testing.zip")
s = smtplib.SMTP(host='blah.blah.yum', port=99)
s.send_message(message)
当我收到电子邮件并尝试打开它时,收到错误消息:
“Windows 无法打开该文件夹,压缩的 Zip 文件夹无效”
在 Stackoverflow 或上找不到类似的错误消息其他地方。我真的很感激一些指导。谢谢!
So first of all I'm not really sure if I'm going about attaching this zip folder the right way. I've kinda hacked together different things together, but I'm getting an error message below which I've linked towards the bottom of my code.
from email.message import EmailMessage
import shutil
message = EmailMessage()
message["From"] = "[email protected]"
message["To"] = "[email protected]"
message["Subject"] = "Testing Zip"
path = "Testing.zip"
with open(path, "rb") as f:
bytes = f.read()
encoded = base64.b64encode(bytes)
message.add_attachment(encoded, maintype='application/zip', subtype='octet-stream', filename="Testing.zip")
s = smtplib.SMTP(host='blah.blah.yum', port=99)
s.send_message(message)
When I receive the email and I try to open it up, I get the error message:
"Windows cannot open the folder, the compressed Zip folder is invalid"
Couldn't find similar error messages on Stackoverflow or other places. I'd really appreciate some direction. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论