Cheersuse Mail::Mailer; # Access sendmail/whatever sub send_email { my ( $error_msg, # input error msg $hostname, # name of this box for sending $prog_full_name, # prog path + name $contact_email, # contact email address $mailer, # mailer object $sender, # sender of email as specified in cfg file $subject, # subject line in email $body_text # actual email msg text ); # Assign input params $error_msg = $_[0]; # 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 = $cfg::params{'ADMIN_EMAIL'}; $sender = "$prog_full_name"; $subject = "$prog_full_name: Error trapped"; $body_text = "This is an automated message:\n\n". "$error_msg\n\n". "Regards,\n$prog_full_name at $hostname\n\n"; # ... and send it $mailer = Mail::Mailer->new(); $mailer->open({ From => $sender, To => $contact_email, Subject => $subject, }) or print "Can't open Mailer for send: $!\n"; print $mailer $body_text; close($mailer) or print "Can't close Mailer: $!\n"; } called as send_email("<your msg here>"); You can optionally specify the mail prog to be used (see the CPAN page +), or let it find one.
In reply to Re: Simplest module for sending email
by chrism01
in thread Simplest module for sending email
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |