gpt4 book ai didi

perl - 使用 perl Email::Sender 发送的 Zip 文件已损坏

转载 作者:行者123 更新时间:2023-12-04 15:13:35 26 4
gpt4 key购买 nike

我正在尝试运行一个脚本,该脚本获取一个文本文件,使用 Archive::Zip 对其进行压缩,然后使用 Email::Sender 通过 smtp 将 zip 文件作为附件发送以创建 mime 消息。

我可以用 perl 发送 txt 文件而不会损坏。我可以发送 perl 手动压缩的文件而不会损坏。我无法通过 perl 发送手动压缩的文件。

我怀疑我的问题在于读取压缩文件或创建 MIME 消息。这是相关代码,它本质上是来自 Email::MIME 概要的代码,其中 $fileToSend 是压缩文件的路径。

有任何想法吗?

use strict;
use warnings;
use Email::MIME;
use Email::Sender::Transport::SMTP;
use Email::Sender::Simple qw(sendmail);
use Archive::Zip qw( :ERROR_CODES :CONSTANTS);
use IO::All;

my $message =
Email::MIME->create(
header_str => [
From => $sender,
To => $recipient,
Subject => $subject,
],
attributes => {
filename => $filename,
content_type => 'application/zip',
disposition => 'attachment',
name => $filename,
},
body => io($fileToSend)->binary->all,
#body => io($fileToSend)->all,
);

最佳答案

终于找到问题了。添加这一行就成功了。

$message->encoding_set( 'base64' );

关于perl - 使用 perl Email::Sender 发送的 Zip 文件已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13730670/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com