I'm trying to run a script that takes a text file, compresses it using Archive::Zip, and sends the zip file as an attachment via smtp using Email::Sender to create a mime message.
I can send txt files in perl without corruption. I can send the file that perl zips manually without corruption. I can not send a manually zipped file through perl.
I suspect my problem is with either reading the zipped file, or creating the MIME message. Here is the relevant code, which is essentially the code from the synopsis of Email::MIME, where $fileToSend is the path to the zipped file.
Any ideas?
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,
);