[sf-perl] MIME::Lite

Thomas Brightbill thomas at brightbill.net
Thu Jul 23 23:46:13 PDT 2009


Peter Loo wrote:

>   my $fileName = "stravinsky09.gif";
>   my $datDir = "/the/path/to/my/file";

>   $message->attach ( Type     => 'application/gif',
>                      Path     => $datDir,
>                      #Encoding => 'base64',
>                      Filename => $fileName,
>                      Disposition => 'attachment' );

I've used MIME::Lite a couple times but have never run across this 
before.  I would suggest changing 'Path' as follows

   Path => $datDir/$filename,

The MIME::Lite documentation says

   Path

     Alternative to "Data" or "FH". Path to a file containing the
     data... actually, it can be any open()able expression. If it
     looks like a path, the last element will automatically be
     treated as the filename. See "ReadNow" also.

In your example above, I'm wondering if it's looking for "file" as the 
filename.

I also found it helpful to turn on debugging with

   $msg->send('smtp','localhost', Debug=>1);


Here's my working test script:

----------------------------------------------------------------------

#!/usr/bin/perl

use strict;

use MIME::Lite;

### Create the multipart "container":
my $msg = MIME::Lite->new(
     From    =>'thomas at brightbill.net',
     To      =>'thomas at brightbill.net',
     Subject =>'A message with 2 parts...',
     Type    =>'multipart/mixed'
);

### Add the text message part:
### (Note that "attach" has same arguments as "new"):
$msg->attach(
     Type     =>'TEXT',
     Data     =>"Here's the spreadsheet file you wanted"
);

### Add the spreadsheet:
$msg->attach(
     Type        =>'application/vnd.ms-excel',
     Path        =>'/home/thomas/testfile.xls',
     Filename    =>'testfile.xls',
     Disposition => 'attachment'
);

$msg->send('smtp','localhost', Debug=>1);

----------------------------------------------------------------------

Thomas

-- 
Thomas Brightbill
thomas at brightbill.net
http://www.brightbill.net



More information about the SanFrancisco-pm mailing list