我想运行一个脚本,需要一个文本文件,压缩它使用Archive :: Zip,并通过使用电子邮件发送zip文件作为附件通过smtp ::发件人创建一个MIME消息。与Perl电子邮件::发件人发送的Zip文件已损坏
我可以在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,
);
什么是发送和接收文件的区别? – Tim
收到的zip文件比发送的压缩文件略小(822 kb比893 kb)。这就是为什么我怀疑io()成为问题。 – Dodd10x
为什么这个复杂的方法,只是发送文件作为附件? – netawater