#!/usr/bin/perl

use Text::Starfish;

die "two arguments required ($#ARGV!=1)" unless $#ARGV == 1;
die "`$ARGV[0]' not a file" unless -f $ARGV[0];
die "`$ARGV[1]' not a file" unless -f $ARGV[1];

$email = getfile($ARGV[1]);
foreach my $r (@{ &read_records("file=$ARGV[0]") }) {
    local $_ = $email;
    s/_(\w+)_/$r->{$1}/eg;
    print "Sending to $r->{EMAIL}\n";
    open(S, "|/usr/sbin/sendmail -t") or die;
    print S;
    close(S);
    `sleep 5`;
}
