#!/usr/local/bin/perl -w
# Send message with attachments

use MIME::Lite;

$TXTFILE="/tmp/textfile";
$ATTFILE="/tmp/binary_file";
$SUBJECT="Your attachment";
$MAILTO="user\@where.ever";

# Create a new multipart message:
$msg = new MIME::Lite 
   From    => "$ENV{LOGNAME}",
   To      => "$MAILTO",
   Subject => "$SUBJECT",
   Type    => 'multipart/mixed';
        
# Add parts (each "attach" has same arguments as "new"):
attach $msg 
   Type     => 'text/plain',   
   Path     => "$TXTFILE";
attach $msg 
   Type     => 'application/octet-stream',
   Encoding => 'base64',
   Path     => "/tmp/$ATTFILE",
   Filename => "$ATTFILE";

# Output the message to sendmail

open (SENDMAIL, "| /usr/lib/sendmail -t -oi");
$msg->print(\*SENDMAIL);
close(SENDMAIL);