#!/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 |