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 ; 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 ; print MAIL "\n"; close(FILE); close(MAIL);