Looking for a test mail generator (unthreaded)

Gary Pentland gary at sgluk.com
Mon Sep 8 17:41:15 IST 2008


This doesn't cover what you need but it is a very basic bulk mail sender...  I posted it in case the bit that sends the mail (at the bottom) may be of use to you.

Hope that is of some help, when I get some time I'll have a go at writing a tool for this purpose aas I'm guessing a few people will find it useful.

Gary

#!/usr/bin/perl -w

use Time::HiRes qw(usleep);

my $fromaddr = "name\@domain.com";
my $pathtorecipfile = "./recipientfile";
my $pathtomsgfile = "./messagefile";

my $messg = read_message_file($pathtomsgfile);

open_recipient_file($pathtorecipfile);

while ($_=<RECIPS>) {
   chomp;
   if (/([-_A-Za-z0-9 at .]+)/) {
      $emailaddy = $1;
   } else {
      print ("Parse error for $_\n");
      next;
   }

   send_email($emailaddy,$fromaddr,$messg);
   usleep 10;

#DEBUG
print ("$fromaddr\t$emailaddy\n");
#DEBUG
}

close_recipient_file();

#####################################################
sub open_recipient_file {

  $RECIPS = $pathtorecipfile;
  open (RECIPS) or die "Can't Open Recipient File $RECIPS:\n";
}

#####################################################
sub close_recipient_file {
  close(RECIPS);
}

#####################################################
sub read_message_file {

  $MESGFILE = $pathtomsgfile;
  open (MESGFILE) or die "Can't Open Message File $MESGFILE:\n";

my @msg = <MESGFILE>;
$message = join "", at msg;

  return $message;
  close(MESGFILE);
}

#####################################################
sub send_email {

  my ($toaddr,$fromaddr,$messg) = @_;

# DEBUG
#  print "DEBUG\n";
#  print "From Address:    $fromaddr\n";
#  print "To Address:      $toaddr\n";
#  print "Message Body     $messg\n";
#  print "END DEBUG\n\n\n";
# DEBUG

  open (SENDMAIL, "|/usr/lib/sendmail -oi -t -odq -f ".$fromaddr) or die "Can't fork Sendmail: $!\n";
  print SENDMAIL "From: $fromaddr\nTo: $toaddr\nReply-To: $fromaddr\n$messg\n";
  close (SENDMAIL) or warn "Sendmail didn't close nicely";
}

#####################################################


More information about the MailScanner mailing list