#!/usr/bin/perl
if ( $#ARGV < 0)
{
print "Usage: mailattach.pl <touser> <fromuser> <subject> <mailfile> <file>","\n";
exit(0);
}
$touser = $ARGV[0];
$fromuser = $ARGV[1];
$subject = $ARGV[2];
$file = $ARGV[4];
print $file;
open(MAILFILE, "$ARGV[3]") || die "can not open mail file" ;
@mailcont = <MAILFILE>;
close(MAILFILE);
$yourmail = "$touser\@alcatel-lucent.com";
open(MAIL, "|/usr/lib/sendmail -t $yourmail") || return 0;
select (MAIL);
print << "EOF";
To: $touser\@alcatel-lucent.com
From: $fromuser\@alcatel-lucent.com
Subject: $subject
@mailcont
EOF
if ( $file ne "" )
{
# File to send to user
open(FILE, "uuencode $file $file |") or die;
while( <FILE>) { print MAIL; };
close(FILE);
}
#and finish sending the mail
close(MAIL);
|