in reply to Re^2: Trouble emailing zip file
in thread Trouble emailing zip file
I was able to get the following to send the zip file but it's corrupted
Does anyone know why the zip file arrives corrupted but I can open the same zip file when using a shell script?
use strict; use warnings; use MIME::Base64; use IO::File; my ($subject, $mach, $from, $to, $attachment, $fh, $content); $subject = "Test Mail"; $from = 'user@email.com'; $to = 'user@email.com'; $attachment = "test.zip"; $fh = "mailbody.txt"; open(FILE, '>', $fh) or die "Cannot open $fh: $!"; print FILE "This is a test"; close(FILE); open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "FROM: $from\n"; print MAIL "TO: $to\n"; print MAIL "Subject: $subject\n"; print MAIL "Content-Type: multipart/mixed; boundary=frontier\n"; print MAIL "--frontier\n"; print MAIL "Content-Type: text/plain; charset=us-ascii\n\n"; open(FILE, '<', $fh) or die "Cannot open $fh: $!"; print MAIL <FILE>; close(FILE); print MAIL "\n\n"; print MAIL "--frontier\n"; chomp(my $basename=`basename $attachment`); print MAIL "Content-Disposition: attachment; filename=$basename\n"; print MAIL "Content-Type: application/octet-stream; name=$attachment\n +\n"; print MAIL "encode_base64( read_file($attachment) )"; open(FILE, '<', $attachment) or die "Cannot open $attachment: $!"; print MAIL <FILE>; print MAIL "\n"; close(FILE); close(MAIL);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Trouble emailing zip file
by Corion (Patriarch) on Jul 05, 2018 at 19:08 UTC | |
by TonyNY (Beadle) on Jul 05, 2018 at 19:46 UTC | |
by Corion (Patriarch) on Jul 05, 2018 at 19:56 UTC | |
|
Re^4: Trouble emailing zip file
by poj (Abbot) on Jul 05, 2018 at 19:53 UTC | |
by TonyNY (Beadle) on Jul 05, 2018 at 21:34 UTC | |
by poj (Abbot) on Jul 06, 2018 at 10:38 UTC |