g_speran has asked for the wisdom of the Perl Monks concerning the following question:

I asked this question a while back but I never got it resolved. It could be the way I asked it. So I will try to explain in detail this time. (Below is the code in reference)

When I send an e-mail using MIME::Lite, I need my log file "available.log" to be an attachment and the body of the e-mail to be the contents of "available.log", which, based upon the below code would contain :

Line 1
Line 2
Line 3

What is happening, still, is that the "available.log", IS properly received as an attachment, BUT the body contents of the e-mail contains:

/export/home/netbackup/logs/available.log

which is the absolute path to the file but not the contents of the log file.

I do have a screen shot for a visual if this would help anyone.

Thanks and sorry for posting again
Gary

use IO::Tee; $OutFile = "/export/home/netbackup/logs/available.log"; $tee = new IO::Tee(\*STDOUT, new IO::File(">$OutFile")); print $tee "Line 1\n"; print $tee "Line 2\n"; Print $tee "Line3\n" ##################################################################### #### Emailing the Reports now ##################################################################### # Send An Email with Attachment MIME::Lite->send('smtp',"$Email_Server",Timeout=>60); $msg = MIME::Lite->new( From => 'Netbackup@company.net', To => "$Email_List", Subject => "$hostname} Available Media Report", Type => 'multipart/mixed'); $msg->attach(Type => 'application/vnd.ms-word', Filename => `basename \"${OutFile}\"`, Path => "$OutFile", ReadNow => 1, Disposition => 'attachment'); $msg->attach(Type => "text/plain", Encoding => 'base64', Data => $OutFile); $msg->send(); ##################################################################### #### End Emailing the Reports #####################################################################

Replies are listed 'Best First'.
Re: MIME::LITE - Body contents and attachments
by chargrill (Parson) on Apr 17, 2006 at 19:01 UTC
    $msg->attach(Type => "text/plain", Encoding => 'base64', Data => $OutFile);

    The above simply adds the contents of the variable $OutFile to the message.

    Looks like you want to print the contents of the file, not the filename itself.

    I'm not restating your question in order to be obtuse, I'm hoping I'm nudging you enough to figure it out yourself.



    --chargrill
    $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}

      Based upon your coment, i'm pretty sure that you were driving at print() and/or print_body(). Unfortunatly, I was not able to get those to work(lack of knowledge). I tried a combination of using Path, FH, readnow, with no success. However, I was able to use data by cat'ing the file to a variable.

      If you would be so kind to possible disclose on how you would have gotten it to work with print() or print_body(), or what ever other means you were driving at, I would appreciate it.

      Thanks
      Gary

      #################################################### #### Emailing the Reports now #################################################### # Send An Email with Attachment $data = `${uxutil}cat ${OutFile}`; #print "Below is the contents of \$data\n$data\n"; MIME::Lite->send('smtp',"$Email_Server",Timeout=>60); $msg = MIME::Lite->new( From => 'Netbackup@company.net', To => "$Email_List", Subject => "${hostname} Robotic Tape Information", Type => 'multipart/mixed'); $msg->attach(Type => 'application/vnd.ms-word', Filename => `basename \"${OutFile}\"`, Path => "$OutFile", ReadNow => 1, Disposition => 'attachment'); $msg->attach(Type => "text/plain", Encoding => 'base64', Data => $data); $msg->send(); #################################################### #### End Emailing the Reports ####################################################

        No, I wasn't driving at print() or print_body(), I was driving at getting the contents of the file into $some_variable that you could dump into the email with Data => $some_variable, which you did, one way or another :)

        Personally, I wouldn't use qx{} to cat the contents of the file, I'd probably read it using your favorite flavor of open and <>, but as always, TIMTOWTDI.

        I'm glad you arrived at your own solution, though :)



        --chargrill
        $,=42;for(34,0,-3,9,-11,11,-17,7,-5){$*.=pack'c'=>$,+=$_}for(reverse s +plit//=>$* ){$%++?$ %%2?push@C,$_,$":push@c,$_,$":(push@C,$_,$")&&push@c,$"}$C[$# +C]=$/;($#C >$#c)?($ c=\@C)&&($ C=\@c):($ c=\@c)&&($C=\@C);$%=$|;for(@$c){print$_^ +$$C[$%++]}
Re: MIME::LITE - Body contents and attachments
by ikegami (Patriarch) on Apr 17, 2006 at 19:04 UTC
    Data => ... is used to attach data which is in memory. To tell MIME::Lite to read the data from a file, use Path => ....