#!/usr/bin/perl

$addresses = "email200603.txt";
#$addresses = "participants.txt";
#$addresses = "test.txt";
open(ADDRESSES, $addresses) || die "Could not open $addresses\n";
while(<ADDRESSES>) {
  chomp;
  ($em) = split;
  $email->{$em} = $em if ( $em );
}

close(ADDRESSES);

$template = "template";
$template = "presenters.txt";
open(TEMPLATE,$template) || die "Could not open $template\n";
$letter = "";
while(<TEMPLATE>) {
  $letter .= $_;
}
close(TEMPLATE);

foreach $person ( sort keys %$email ) {
  $_ = $letter;
  s/XXXX/$person/;
  open( MAIL, '| Mail -s "CTC conference, Oxford 1-3rd July 2003" ' . $email->{$person} ) || die "Could not email $email->{$person}\n";
  print MAIL $_;
  close(MAIL);
  warn "mailed $person at $email->{$person}\n";
}
