Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zip file sent with perl Email::Sender is corrupted

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,
      );
like image 504
Dodd10x Avatar asked Dec 05 '12 19:12

Dodd10x


1 Answers

Found the problem finally. Adding this line did the trick.

$message->encoding_set( 'base64' );
like image 176
Dodd10x Avatar answered Oct 17 '22 09:10

Dodd10x