use strict; ##------------- Global my @email_message; my %headerz; my $new_recip; my $orig_recip; my $linelimit = 234; my $linecount = 0; ##------------- Edit these my $bcc = ''; my $replyto = 'no_replies@yourdomain.com'; my $from_address = 'your AutoResponse '; my $datestring = &datestring; my $saved_file_name = "/path/mailmsg-$datestring.txt"; ##------------- main &save_mail; &header_mgr; #-------------> Edit these too <------------- my $subject = "Your submission to $orig_recip"; my $bodytext = qq|\n your message body to send as autoreply\n |; #-------------------------------------------- &dispatch or die "email dispatch failed: $!"; ##------------- end ##--------------- SUBS ### mail collector sub save_mail { while ( ) { chomp; push @email_message, $_; $linecount++; } if ( $linecount <= $linelimit) { open SAVEDMAIL, '>', $saved_file_name or warn("could not open output file $!"); print SAVEDMAIL $_,"\n" for @email_message; close SAVEDMAIL; } return @email_message; } ### Timestamp for disk file sub datestring { my ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); my $timeformat = sprintf( "%02d%02d%04d-%02d_%02d_%02d", $mon+1,$mday,$year+1900,$hour,$min,$sec ); return $timeformat; } ### Collect original headers into a hash sub header_mgr { foreach ( @email_message ) { /(^From: )(.*$)/ ? $headerz{from_address} = "$2" : 1; /(To: )(.*$)/ ? $headerz{orig_recip} = "$2" : 1; /(^Reply-To: )(.*$)/ ? $headerz{replyto} = "$2" : 1; /(^cc: )(.*$)/i ? $headerz{cc} = "$2" : 1; /(^Date: )(.*$)/ ? $headerz{datestamp} = "$2" : 1; /(^Subject: )(.*$)/ ? $headerz{subject} = "$2" : 1; } ( defined $headerz{'reply_to'} ) ? $new_recip = $headerz{'replyto'} : $new_recip = $headerz{'from_address'}; ( defined $headerz{'orig_recip'} ) ? $orig_recip = $headerz{'orig_recip'} : 1; } ##Mail sending routine sub dispatch { open(MAILPIPE,"|/usr/sbin/sendmail -t"); print MAILPIPE "To: $new_recip\n"; print MAILPIPE "From: $from_address\n"; print MAILPIPE "Bcc: $bcc\n"; print MAILPIPE "Subject: $subject\n"; print MAILPIPE "\n"; print MAILPIPE "$bodytext\n"; print MAILPIPE "\n-----------------------------------\n\n"; print MAILPIPE "Original message of $linecount lines, was sent to $orig_recip.\n"; print MAILPIPE "\n-----------------------------------\n\n"; close(MAILPIPE); } __END__