#!/usr/local/bin/perl -w # Takes a single column input file (stdin) # with properly formatted email addresses and emails a canned # message out one per address with a 15 second delay between each one. # Sets the Reply-to and From to $from value. Logs improperly formatted # addresses to a log file. # # Revision history # # K. P. Inscoe 1.0 - Aug. 16, 2002 Create original. # K. P. Inscoe 1.1 - Dec. 3, 2002 Changed the output to the logfile as # an append operation. # K. P. Inscoe 1.2/1.3 - July 2, 2003 Added error output from close of sendmail # pipe and decreased the delay to 1 second. # globals use File::Find; $from = "Customer_Care\@Harcourt.com"; $replyto = "Customer_Care\@Harcourt.com"; $title = "The Psychological Corporation"; $subj = "The Psychological Corporation Announces New PsychCorp.com"; $log = "spamit.log"; $msg = "tpcmsg.txt"; $vers="1.3"; $count=0; $ncount=0; $tcount=0; #$delay=10; $delay=1; # main $date = localtime; open(LOG, ">>$log") or die "cannot open $log for writing - $!\n"; print "SpamIt.pl: vers $vers starting at $date\n"; print LOG "SpamIt.pl: vers $vers starting at $date\n"; &memorize_message(); while (<>) { chomp; $tcount++; if ( $_ =~ /^(([^\-][\w\-]*?\.?){1,})[^-](\@{1})([^\-][\w+\.\-])[^\2]{1,}[^\-]$/ ) { print LOG "To: $_\n"; &send_msg($_); $count++; } else { print LOG "Bad address: $_\n"; $ncount++; } } print "SpamIt complete. $count messages sent ($ncount rejected email address out of $tcount total).\n\n"; print LOG "SpamIt complete. $count messages sent ($ncount rejected email address out of $tcount total).\n\n"; $date = localtime; ($user,$system) = times; print "$date elapsed time: user: $user secs, system: $system secs\n"; print LOG "$date elapsed time: user: $user secs, system: $system secs\n"; close(LOG); sub memorize_message { open(MSG, "<$msg") or die "cannot open $msg for reading - $!\n"; @MSGBUF = ; close(MSG); print LOG "*** message is ***\n\n"; print LOG "@MSGBUF\n"; } sub ticker { $x = $flip / $flipfactor; if ( $flip == ( $x * $flipfactor ) ) { $flip++; if ( $cycle==0 ) { print "\052\010"; $cycle++; } if ( $cycle==1 ) { print "\134\010"; $cycle++; } if ( $cycle==2 ) { print "\174\010"; $cycle++; } if ( $cycle==3 ) { print "\057\010"; $cycle++; } if ( $cycle==4 ) { print "\055\010"; $cycle=0; } } $flip++; } sub send_msg { my $to = $_; # open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") open(SENDMAIL, "|/usr/lib/sendmail -t") or die "Can't fork sendmail: $!\n"; print SENDMAIL "From: $title <$from>\n"; print SENDMAIL "Reply-to: $replyto\n"; print SENDMAIL "Subject: $subj\n"; print SENDMAIL "To: $to\n"; print SENDMAIL "Content-type: text/plain\n\n"; foreach $line (@MSGBUF) { print SENDMAIL "$line"; } # print SENDMAIL "@MSGBUF\n"; close(SENDMAIL) or warn "sendmail didn't close nicely: $!"; sleep($delay); }