Important alert: (current site time 7/15/2013 9:08:13 PM EDT)
 

VB icon

Autoresponder

Email
Submitted on: 7/30/2000 12:45:04 AM
By: Found on the World Wide Web 
Level: Intermediate
User Rating: By 3 Users
Compatibility: 5.0 (all versions), 4.0 (all versions), 3.0 (all versions), Pre 3.0
Views: 21995
 
     A script for receiving a mail and immediately replying
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
=**************************************
= Name: Autoresponder
= Description:A script for receiving a mail and immediately replying
= By: Found on the World Wide Web
=**************************************

#!/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 <<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' => 0, 'MailFrom' => 'KEEP');
my @headers = @{$msg->head()->header()};
my @body = @{$msg->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->reply();
$msg->body(\@message);
print("Replying to $REPLY_TO.\n") if $opt_verbose;
$msg->head()->replace('Reply-To', $REPLY_TO);
print("Replying message:\n", $msg->as_string()) if $opt_verbose;
$msg->smtpsend() unless $opt_debug;


Other 100 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

7/21/2003 4:47:29 AMPhoenix Software

This is a gem.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.