#!/usr/local/bin/perl -Tw # mailbot.pl -- a simple mailbot program # By Chris Candreva # Stardate 0709.95 # ---------------- # Minor updates by Brian Lavender from the WEBMASTERS list # 06/26/00 # ---------------- # # 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 # # BEGIN { $ENV{PATH} = '/bin:/usr/bin:/usr/lib'; # Set the path, so we know where we are # getting our commands } use strict; unless ($ARGV[0]) { open (OUT,"|/usr/bin/mail -s 'Error!' postmaster"); print OUT "There is a misconfigured mailbot. Please fix.\n\n\n"; close OUT; exit 1; } my $mailfile = $ARGV[0]; while() { if (s/^From: //) { s/[\012\015]|^ *//g; #Remove all CR and LF my $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;