Please visit our sponsor
UNKNOWN =************************************** = Name: Autoresponder = Description:A script for receiving a mail and immediately replying = By: Found on the World Wide Web = = = Inputs:None = = Returns:None = =Assumes:None = =Side Effects:None =************************************** #!/usr/bin/perl =pod =head1 NAME autoresponder - A scrtipt for receiving a mail and immediately replying. =head1 SYNOPSIS autoresponder [options] [filename] =head1 DESCRIPTION While installing a new mail server or client you typically are sending and receiving test mails over and over again. Even worse, you sometimes have to do a phonecall and ask someone for sending a mail to you. This script will help you in some cases by setting up an email address like autoresponder@company.com that will receive email addresses and immediately reply it back. =head1 INSTALLATION Install the prerequisite Perl modules, in particular Graham Barr's excellent Mailtools package. L<mail::internet(3)>. In /etc/mail/aliases or /etc/aliases, put lines like this: autoresponder: "| /usr/local/bin/autoresponder" owner-autoresponder: /dev/null autoresponder-owner: /dev/null Then do a "newaliases". Edit the autoresponder script and change the reply-to address to point back to one of the owner addresses. This should have the advantage that you won't see error messages generated by the autoresponder. =head1 SCRIPT CATEGORIES mailstuff =head1 PREREQUISITES The MailTools package, in particular the Mail::Internet module. L<mail::internet(3)>. =head1 OSNAMES any OS using sendmail or a compatible mail server =head1 AUTHOR Jochen Wiedmann Am Eisteich 9 72555 Metzingen Germany Email: joe@ispsoft.de =head1 SEE ALSO L<mail::internet(3)>, L<aliases(5)> =cut use strict; ############################################################################ # #Configurable section # ############################################################################ my $REPLY_TO = 'autoresponder-owner@neckar-alb.de'; # #Use an entry like # # autoresponder-owner: /dev/null # #to suppress error messages from autoresponders replies. # ############################################################################ use Mail::Internet (); use Getopt::Long (); use vars qw($opt_debug $opt_verbose $opt_help); sub Usage() { print &lt;<eof; usage: autoresponder [options] [filename] reads an email from [filename] (default: stdin) and replies to the sender. possible options are: --debug turn on debugging mode. (suppresses actions) --help print this help message. --verboseturn on verbose mode. eof exit 1; } eval { getopt::long::getoptions('debug', 'verbose', 'help') }; usage() if $@ || $opt_help; $opt_verbose="1" if $opt_debug; my $fh; if (@argv) { my $file="shift" @argv; open(file, "<$file") or die "failed to open $file: $!"; $fh="\*FILE;" print "reading mail from $file.\n" if $opt_verbose; } else { $fh="\*STDIN;" print "reading mail from stdin.\n" if $opt_verbose; } my $msg="Mail::Internet-">new($fh, 'Modify' =&gt; 0, 'MailFrom' =&gt; 'KEEP'); my @headers = @{$msg-&gt;head()-&gt;header()}; my @body = @{$msg-&gt;body()}; my @message = ("\n", "Your mail was received by the autoresponder.\n", "\n", "Your headers have been:\n", @headers, "End of headers\n", "\n", "Your body follows:\n", @body ); $msg = $msg-&gt;reply(); $msg-&gt;body(\@message); print("Replying to $REPLY_TO.\n") if $opt_verbose; $msg-&gt;head()-&gt;replace('Reply-To', $REPLY_TO); print("Replying message:\n", $msg-&gt;as_string()) if $opt_verbose; $msg-&gt;smtpsend() unless $opt_debug;