########################################################################### # In: # Out: # Works but no file attached. sub mailfile {my($replyaddr,$fnout,$subjparam)=@_; # mailsender() my(@a,@b,$i,$j,$k,$procname,$result,$s,$t); my(%data,$body,$divline,$fn,$hashcnt,$key,$err,$sender,$to); my($prefixsp); $procname="mailfile"; $prefixsp=' '; # Prefix spaces to indent msgs nicely. $to=$replyaddr; # Send email to this address. if (len($to)<3) # Email must be at least n ctrs. { $s=$prefixsp."$procname ERROR: To address is missing or invalid."; writeerr($s); exit 10; } $divline="========================================\r"; $s=$prefixsp."$procname: Going to create Mail::Sender "; if (len($fnout)>0) { $s.="with file $fnout"; } $s.="..."; writeerr("$s"); # DEBUG if (! -e $fnout) { $s="$procname ERROR: $fnout does not exist"; writeerr($s); exit 1; } $sender=new Mail::Sender(); # Line feeds for Outlook 2012 require \r. $body=''; $body.="Log follows. Look for lines that say ERROR.\r"; $body.=$divline; $body.="\r.\r"; # Required for email. Period on line by itself. if (len($fnout)>0) { if (-e $fnout) # If $fnout exists then... { @a=split('/',$fnout); $fn=$a[$#a]; # Drop directories from $fnout. $s=$prefixsp."$procname: Attaching output file: $fnout"; # DEBUG writeerr($s); $result=0; # Was $result=$sender->MailFile(...) $result=$sender->MailFile( { file=>$fnout, client=>'xxxclient', smtp=>$server, port=>80, from=>$fromaddr, replyto=>$fromaddr, authid=>$authuser, authpwd=>$authpw, auth=>'LOGIN', debug=>'debugt.txt', ctype=>'application/vnd.ms-excel', multipart=>'multipart/mixed', encoding=>'base64', disposition=>"attachment; filename=$fnout", to=>$to, subject=>$subjparam, msg=>$body }) and print $prefixsp."$procname: Mail sent ok\n"; if (($result<0) ) { $s=$prefixsp."$procname ERROR: ". "$result on MailFile(): '". trim($Mail::Sender::Error)."'\n"; writeerr($s); $sender->Close(); exit 1; } } # if -e fnout else { $s=$prefixsp."$procname ERROR: $fnout does not exist."; writeerr($s); $sender->Close(); exit 1; } } else { print "Filename $fnout was blank\n"; } # else # Now close connection. $sender->Close(); if ($@) { $s=$prefixsp."$procname ERROR: Could not make new Mail::Sender. $@"; writeerr($s); exit 1; } else { $s=$prefixsp."$procname: Sent email to $to"; if (len($fnout)>0) { $s.="\n".$prefixsp." with file $fnout"; } writeerr($s); } writeerrfile('tmailsend'); return; # mailfile }