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

This one I have tested over and over and the path/filename of the file attachment are correct. I'm trying to send a mail message in Perl and an attach a simple text file to it. The code is as follows:
use MIME::Lite ... ... ... sub benchMailReport { my $msg = new MIME::Lite( From => $defaults{EMAIL_FROM}, To => $defaults{EMAIL_TO}, Subject => $defaults{EMAIL_SUBJECT}, Type =>'multipart/mixed' ); $msg->attach( Type =>'TEXT', Disposition =>'inline', Path => $defaults{REPORT_DIR}, Filename => $defaults{REPORT_FILE_NAME} ); my ($result) = $msg->send(); }
The result is that it sends the e-mail message properly, but when I open the attached file it is blank. But again I have tested the Path/Filename combination over and over again and they are correct, they point to a valid file. I would appreciate any help, thanks a lot. Brent.

Replies are listed 'Best First'.
Re: Using MIME::Lite in perl.
by hossman (Prior) on Jul 17, 2002 at 01:34 UTC
    i'm not an extensive user of MIME::Lite, but i have a couple of thoughts...
    1. Are you sure you understand what the Path & Filename parameters to attach are for? 'Path' should be the full path of your file, not just a directory name -- 'Filename' is just what label the file gets in the email.

      (I'm guessing this is your REAL problem, the rest are just alternate suggestions)

    2. In my experiments, MIME::Lite doesn't deal well with "multipart/mixed" msgs that only have 1 part, so unless you are attaching more things then you show you might try this...
      $msg = MIME::Lite->new( From =>'me@myhost.com', To =>'you@yourhost.com', Cc =>'some@other.com, some@more.com', Subject =>'Helloooooo, nurse!', Type =>'TEXT', Path =>'/your/file/name', );
    3. on my installation, MIME::Lite (v2.104) seems to be creating malformed msg headers -- putting in an extra blank line after the subject, if that's happening on your system, it's probably confusing your mail reader.
    4. you might wnat to take a look at the "ReadNow" option of $msg->attach, if there's a chance that your file is getting deleted at anypoint in your script (prior to the $msg->send() call)
Re: Using MIME::Lite in perl.
by kodo (Hermit) on Jul 17, 2002 at 07:14 UTC
    I would suggest you to read the doc of MIME::Lite. But to get your code to work, I often send text/html-attached mails and never had a problem with:
    my $msg = new MIME::Lite( From => $defaults{EMAIL_FROM}, To => $defaults{EMAIL_TO}, Subject => $defaults{EMAIL_SUBJECT}, Type => 'text/plain' ); $msg->attach( Type => 'text/html', Encoding => '8bit', Path => "$defaults{REPORT_DIR}$defaults{REPORT_FILE_N +AME}", ); MIME::Lite->send( 'smtp', 'localhost', Timeout => 20 ); my ($result) = $msg->send();


    giant
      Completely petty and insignificant, but
      Path => "$defaults{REPORT_DIR}$defaults{REPORT_FILE_NAME}",
      is better written (completely IMO) as
      Path => $defaults{REPORT_DIR}.$defaults{REPORT_FILE_NAME},
      :-)

      Yves / DeMerphq
      ---
      Writing a good benchmark isnt as easy as it might look.

Re: Using MIME::Lite in perl.
by Cine (Friar) on Jul 17, 2002 at 00:34 UTC
    Shouldn't Disposition in the attachment be 'attachment' instead of 'inline'?

    T I M T O W T D I
      Hi Cine, I just tried is using 'attachment' for disposition and it still didn't work. Any other suggestions?
        My only other idea is that you have missunderstood the filename/path as someone else also writes. Could you write the values you use here?

        T I M T O W T D I