in reply to Re^3: Trouble emailing zip file
in thread Trouble emailing zip file

Why the second print statement ?

print MAIL "encode_base64( read_file($attachment) )"; open(FILE, '<', $attachment) or die "Cannot open $attachment: $!"; print MAIL <FILE>;

Try replacing those 3 lines with

open(FILE, '<', $attachment) or die "Cannot open $attachment: $!"; binmode FILE; while (read(FILE, my $buf, 60*57)) { print MAIL encode_base64($buf); }
poj

Replies are listed 'Best First'.
Re^5: Trouble emailing zip file
by TonyNY (Beadle) on Jul 05, 2018 at 21:34 UTC
    Thanks poj but the attachment is still arriving corrupted.

      Try

      #!/usr/bin/perl use strict; use warnings; use MIME::Base64; use IO::File; use File::Basename 'basename'; my $from = ''; my $to = ''; my $subject = "Test Mail"; my $mailbody = "This is a test"; my $attachment = "test.zip"; my $basename = basename($attachment); open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL << "EOF"; From: $from To: $to Subject: $subject Content-Type: multipart/mixed; boundary=frontier --frontier Content-Type: text/plain; charset=us-ascii $mailbody --frontier Content-Disposition: attachment; filename=$basename Content-Transfer-Encoding: base64 Content-Type: application/octet-stream; name=$attachment EOF open FILE, '<', $attachment or die "Cannot open $attachment: $!"; binmode FILE; while (read(FILE, my $buf, 60*57)) { print MAIL encode_base64($buf); } close FILE; print MAIL "\n--frontier\n"; close MAIL;
      poj