###################################################################### +##### # 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 invali +d."; 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 }
Thank you!

Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)

In reply to Mail::Sender not attaching XLS file by bulrush

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.