#!/usr/bin/perl # mailbot.pl -- a simple mailbot program # By Chris Candreva # Stardate 0709.95 # # This program is now public domain, copy it, change it, do whatever you # want with it. If you add features, I would like to know about them. # # usage: mailbot.pl mailfile # # This is usually placed in a sendmail aliases file, such as the following: # # support: chris, "|/usr/local/bin/mailbot.pl /home/chris/techmail.txt" # # Put any real people who should also receive the mail in front. # The mailfile should start as follows: # # From: A Real Name # Subject: The Subject of the message # # Your message starts here, to the end of the file # # unless ($ARGV[0]) { open (OUT,"|/usr/ucb/mail -s 'Error!' postmaster"); print OUT "There is a misconfigured mailbot. Please fix.\n\n\n"; close OUT; exit 1; } $mailfile = $ARGV[0]; while() { if (s/^From: //) { s/[\012\015]|^ *//g; #Remove all CR and LF $to = $_; open (OUT, "|/usr/lib/sendmail -oi -t"); open (IN, $mailfile ); #Read and display FROM line. $_ = ; print OUT $_; print OUT "To: $to\n"; while () { print OUT $_; } close IN; close OUT; } } exit 0;