Well, it works from the prompt but not via cron.
use strict;
use warnings;
use MIME::Lite;
# from the link you gave
sub get_login_env {
local %ENV;
my $shell = shift || (getpwuid($<))[8];
my $env = `echo env | perl -e 'exec {"$shell"} -sh'`;
if (wantarray) {
my @pieces = ( $env =~ m/^(.*?)=((?:[^\n\\]|\\.|\\\n)*)/gm );
s/\\(.)/$1/g foreach @pieces;
return @pieces;
}
else {
return $env;
}
}
%ENV = (%ENV, get_login_env());
my $mailvar = $ENV{'TESTMAILUSRS'};
my @mailUsers;
my $msg = new MIME::Lite();
$msg->build(
From => 'us@here.com',
Subject => 'Email from perl via cron',
Type => 'text/html',
Data => 'testing',
Debug => 1
);
for (split /[\s\n]/, $mailvar){
if($_){
$msg->add(To => $_);
}
}
eval { $msg->send };
die "MIME::Lite->send failed: $@\n" if $@;
|