#!/usr/bin/perl # $Id: mailfwd.pl,v 1.6 2004/04/10 18:16:13 Gunnar Hjalmarsson Exp $ use strict; my ($targetURL, $errorfile, $password, $sendmail, $to, $from, $subject, $msg); ##--------------------------------------------------------------------------- $targetURL = 'http://www.mydomain.com/cgi-bin/mhonarc/mhastart.pl'; $errorfile = '/www/htdocs/cgi-bin/mhonarc/errors.txt'; $password = 'abc'; $sendmail = '/usr/sbin/sendmail'; $to = 'abc@mydomain.com'; $from = 'webmaster@mydomain.com'; $subject = 'Addition to archive failed'; $msg = 'Some error occurred when archiving the following message:'; ##--------------------------------------------------------------------------- my $newmail = join ('', ); use LWP::UserAgent; if ($newmail =~ /^From /) { $password .= "\n" if $password; # Forward to $targetURL as a HTTP request my $ua = new LWP::UserAgent; $ua->timeout(60); my $req = new HTTP::Request(post => $targetURL); $req->content_type('application/x-www-form-urlencoded'); $req->content($password . $newmail); my $resp = $ua->request($req); # If no success response unless ($resp->is_success) { my $nonote = ''; # Notify about the failure if (-f $sendmail and -x _) { open (MAIL, "| $sendmail -t"); print MAIL "To: $to\nFrom: $from\nSubject: $subject\n\n", "$msg\n\n$newmail\n"; close (MAIL); } else { $nonote = ("Incorrect path to sendmail; no notification sent.\n"); warn $nonote; } # Save the message for later fix open (FILE, ">>$errorfile") or die "Can't open $errorfile\n$!"; print FILE $resp->status_line, "\n$nonote\n$newmail\n\n"; close (FILE); } }