当我通过电子邮件message模块将zip文件夹发送给我自己时,请遇到无效的zip文件错误

发布于 2025-01-21 03:10:37 字数 988 浏览 2 评论 0原文

首先,我不确定是否要以正确的方式附加此 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文