sub sendmail { my ($arg_ref) = @_; print "Running sendmail()\n" if ($onterm && ($debug & $DEBUG_NOTIFY_MAILS)); =pod This subroutine is the interface to the mail sender functionality. Depending on incoming parameters it sends just a message or a message with attachment =cut my $sendfailed = 0; my $sender = new Mail::Sender( {from => $arg_ref->{from}, smtp => $arg_ref->{smtp}, port => $arg_ref->{port}, auth => $arg_ref->{auth}, authid => $arg_ref->{authid}, authpwd => $arg_ref->{authpwd}, auth_encoded => $arg_ref->{auth_encoded}, encoding => 'Quoted-printable', charset => $charset, }); if ($sender > 0) { print "\$sender created OK\n" if ($onterm && ($debug & $DEBUG_NOTIFY_MAILS)); if ((defined $arg_ref->{file}) && (-f $arg_ref->{file})) { # Send message with attachment print "sending mail with attachment\n" if ($onterm && ($debug & $DEBUG_NOTIFY_MAILS)); $sender->MailFile({to => $arg_ref->{to}, subject => $arg_ref->{subject}, encoding => "Base64", ## read this from parameters? msg => encode($charset,$arg_ref->{msg}), file => $arg_ref->{file} }); if (defined $sender->{'error'} ){ logerror( "Error sending mail with attachment '$arg_ref->{file}' to $arg_ref->{to}: Error code $sender->{'error'} ($sender->{'error_msg'})"); $sendfailed = 1; } else { loginfo("File \"$arg_ref->{file}\" successfully emailed to $arg_ref->{to}"); } } else { #send a message with no attachment $arg_ref->{msg} .= "\n\nAttempt to send file '$arg_ref->{file}' abandoned: File does not exist" if defined $arg_ref->{file}; print "sending mail without attachment\n" if ($onterm && ($debug & $DEBUG_NOTIFY_MAILS)); $sender->MailMsg({to => $arg_ref->{to}, subject => $arg_ref->{subject}, encoding => "Quoted-printable", ## read this from parameters? msg => encode($charset,$arg_ref->{msg}), }); if (defined $sender->{'error'} ){ logerror( "Error sending mail to $arg_ref->{to}: Error code $sender->{'error'} ($sender->{'error_msg'})"); $sendfailed = 1; } } } # if ($sender > 0) else { logerror("Could not establish mail sender to $arg_ref->{to}: Error code $sender ($Mail::Sender::Error)"); $sendfailed = 1; } return ($sendfailed) ? 0 : 1; } #### Running MailChangeNotifications Running sendmail() $sender created OK sending mail without attachment