use warnings; use strict; #### use strict; use warnings; # Define constants my $address_file = "email.txt"; my $message_text = "message.txt"; my $from_addr = "anywhere@home.com"; my $mailhost = "localhost"; # Always check to see if file opened or not open(MSG, "$message_text") || die "Could not open $message_text! $!\n"; my $subject; my $body; LINE: while() { if /^subject:(.*)/ { $subject = $1 and next LINE}; $body .= $_; } close(MSG); open(LIST, "$address_file") || die "Could not open $address_file! $!\n"; # Send an email for each address in the file # Note we're not doing any validation on addresses while() { chomp; my $sender = Net::SMTP->new("$localhost"); $sender->mail("$from_addr"); $sender->to("$_"); $sender->data(); $sender->datasend ("From: Home\n"); $sender->datasend ("Subject: $subject\n\n"); $sender->datasend ("$body\n"); $sender->dataend(); $sender->quit(); } close(LIST);