Sendmail通过perl脚本

时间:2012-05-29 14:33:14

标签: linux perl

我正在使用这个perl脚本来获取一个文本文件,其中包含很少的属性但是你可以看到我使用sendmail选项发送邮件,但问题是它没有发送邮件。实际上我想要邮件的内容.txt在我的邮件正文中发送或作为附件,是否可以通过sendmail发送附件。@ write_array具有邮件正文的内容。

 #!/usr/bin/perl

use strict;
use warnings;
my $qtool = "/usr/local/bin/qtool.pl";
my $mqueue_directory = "/var/spool/mqueue/";
my $messages_removed = 0;
my @rf_id;
my @date;
my $temp;
my @write_array;
my $to;
my $from;
my $subject;
use Untaint;
use File::Find;
# Recursively find all files and directories in $mqueue_directory
my %options= (
wanted => \&wanted,
untaint => 1
);
find(\&wanted, $mqueue_directory);

sub wanted {
   # Is this a qf* file?
   if ( /^qf(\w{14})/ ) {
      my $qf_file = $_;
      my $queue_id = $1;
      $qf_file=~/(.*)/ ;
      $qf_file=$1;
      my $deferred = 0;
      my $from_postmaster = 0;
      my $delivery_failure = 0;
      my $junk_mail = 0;
      open (QF_FILE, $_);
      while(<QF_FILE>) {
         chomp;
         if ( /^MTemporarily/ | /^Mhost map: lookup/ | /^MUser unknown/ )
         {
         $temp=$_.':';
         }




         $deferred = 1 if ( /^MTemporarily/ | /^Mhost map: lookup/ | /^MUser unknown/ | /^MDeferred/ );
         $delivery_failure = 1 if \
            ( /^H\?\?Subject: DELIVERY FAILURE: (User|Recipient)/ );
         if ( $deferred && $delivery_failure ) {
            $junk_mail = 1;
                     }
      $temp.=$qf_file.':';
      if($junk_mail){
      while(<QF_FILE>){
      chomp;
      if(/rRFC822;/){
      $temp.=subdtr($_,9)
      }
      if(/H??Date:/){
      $temp.=':'.substr($_,9);
      push @write_array, $temp."\n";
      }
      }
      }
      }
      close (QF_FILE);
      my $subqueue_id = substr($queue_id,9);
      if ($junk_mail) {
         print "Removing $queue_id...\n";
         $ENV{"PATH"}="/bin/:/usr/bin/:/usr/local/bin/:/var/spool/mqueue/";
         my $df_file = 'df' . $queue_id ;
         print "Removing $df_file... \n";
         system ("rm $mqueue_directory$qf_file");
         system ("rm $mqueue_directory$df_file");
         $messages_removed++;
      }
   }
}
open (MYFILE,">/scripts/mail.txt");
print MYFILE "@write_array";
close (MYFILE);
$to='yagya@mydomain.in';
$from='system@mydomain.in';
$subject='deleted mails';
$ENV{"PATH"}="/usr/sbin/:/usr/sbin";
open(MAIL,"|/usr/sbin/sendmail -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "@write_array\n";
close(MAIL);

print "\n$messages_removed total \"double bounce\" message(s) removed from ";
print "mail queue.\n";

0 个答案:

没有答案