zabbix 调用的发邮件脚本

zabbix:/etc/zabbix/alertscripts# cat smail.pl 
#!/usr/bin/perl 
use Net::SMTP;
   use HTTP::Date qw(time2iso str2time time2iso time2isoz);  
# mail_user should be [email protected]
sub send_mail{
       if ( $#ARGV < 2 ){
        print "please input 收件人 主题  内容!\n";
                exit(-1);
                    }
    my $name= $ARGV[2];
my $CurrTime = time2iso(time());
    my $to_address  = shift;
    my $mail_user   = '[email protected]';
    my $mail_pwd    = 'xxxxxx';
    my $mail_server = 'smtp.exmail.qq.com';

    my $from    = "From: $mail_user\n";
    my $subject = "Subject:$ARGV[1]";
    my $info = "$CurrTime--$name ";
     my $message = <<CONTENT; 
     $info
CONTENT
    my $smtp = Net::SMTP->new($mail_server);

    $smtp->auth($mail_user, $mail_pwd) || die "Auth Error! $!";
    $smtp->mail($mail_user);
    $smtp->to($to_address);

    $smtp->data();             # begin the data
    $smtp->datasend($from);    # set user
    $smtp->datasend($subject); # set subject
    $smtp->datasend("\n\n");
    $smtp->datasend("$message\n"); # set content
    $smtp->dataend();
    $smtp->quit();
};
$receive=$ARGV[0];
@arr_mail=( "$receive",'[email protected]');
foreach (@arr_mail){
send_mail $_;
}; 

你可能感兴趣的:(zabbix 调用的发邮件脚本)