????

Your IP : 216.73.216.174


Current Path : /usr/lib/raider/Raider/Notification/
Upload File :
Current File : //usr/lib/raider/Raider/Notification/Email.pm

use strict;
use warnings;

package Raider::Notification::Email;
use base qw( Raider::Notification );

=head1 NAME

Raider::Notification::Email - Send an email notification

=head1 DESCRIPTION

Send an email notification

=head1 USAGE

use Raider::Notification::Email;
my $emailObj = Raider::Notification::Email->new();

=head1 METHODS

=head2 send_notification(\%args)

Send an email notification to contact_email

=cut

sub send_notification {
  my $self = shift;
  my $opts = shift;

  my $mail_cmd = [ 'mail' ];
  my $mail_cmd_check = $self->in_path({ cmds => $mail_cmd, mode => 'nofatal' });
  if ( $mail_cmd_check ne 'present' ) {
    my $msg = "A notification event was made, but I am unable to create the notification. This means that the API host is down, and the system mail command is not in the \$PATH.";
    unless ( $opts->{no_log} ) {
      $self->logger({ cat => 'c', msg => $msg });
    }
    else {
      print STDERR "$msg\n";
      $self->do_exit();
    }
  }

  # FS#5808 Carriage return causes mailx to send binary attachment.
  $opts->{message} =~ s/\r//g;

  my $conf_file = $self->read_conf_file();
  # Yes, this would normally be done with a module of some sort so we don't have to call system
  # commands for a task like this. However, i'm doing it this way so we don't have to worry about
  # packaging extra modules. If someone can find a built in core perl module for handling mail we
  # can easily add it here (that is also in 5.8.8). --ssullivan 01/24/2012
  my $mail_cmd_stderr = `echo \"$opts->{message}\" | mail -s \"$opts->{subject}\"  \"$conf_file->{'contact_email'}\" 2>&1 1>/dev/null`;
  if ( $? != 0 ) {
    my $msg = "Error sending email notification, got STDERR: $mail_cmd_stderr";
    unless ( $opts->{no_log} ) {
      $self->logger({ cat => 'c', msg => $msg });
    }
    else {
      print STDERR "$msg\n";
      $self->do_exit();
    }
  }
  else {
    unless ( $opts->{no_log} ) {
      $self->logger({ cat => 'i', msg => "Successfully sent email notification." });
    }
    else {
      print "Successfully sent email notification.\n";
    }
  }
}


1;