Output is:#!/usr/bin/perl -w use MIME::Lite; # send mail attachments use Sys::Hostname; # Used to insert hostname in emails use Cwd; # Get current full dir for error msgs use strict; # Enforce declarations my ( $hostname, # name of this box for sending $prog_full_name, # prog path + name $contact_email, # contact email address $msg, # msg object $sender, # sender of email $subject, # subject line in email $body_text # actual email msg text ); # Get hostname anyway we can using Sys::Hostname; # tries syscall(SYS_gethostname), `hostname`, `uname -n` $hostname = Sys::Hostname::hostname(); # Get program full path name $prog_full_name = cwd()."/${0}"; # Set the fields required by Mailer... $contact_email = ''; $sender = "$prog_full_name"; $subject = "$prog_full_name: Asset Mgr Report"; $body_text = "This is an automated message:\n\n"; # ... and send it # Header $msg = MIME::Lite->new( From => $sender, To => $contact_email, Subject => $subject, Type =>'multipart/mixed' ); # Body Content $msg->attach( Type => 'TEXT', Data => $body_text ); # Attachment $msg->attach( Type => 'text/plain', Path => "/home/chrism/t.csv", Filename => "t.csv", Disposition => 'attachment' ); # Send $msg->send or print "Error: $@\n";
where 1st line appears in logfile, 2nd line shows error text is not in $@.sendmail: fatal: No recipient addresses found in message header Error:
If I try this instead
I only get the logged msg. My own error msg does not appear.eval{$msg->send}; print "Error: $@\n" if($@);
In reply to Re^2: Trap the error msg from Mime::Lite
by chrism01
in thread Trap the error msg from Mime::Lite
by chrism01
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |