Check out merlyn's article on the subject; I found it very useful when working on a similar project.
While working on the project, I made some observations you may find helpful (note that the following code has been simplified from the final, so certain typos may have been made):
if ( $copiesto )
{ $msg->add( CC => $copiesto ); }
$msg->attach
( Disposition => 'attachment',
Type => $sentinfo->{ 'Content-Type' },
Encoding => 'base64',
Filename => $sentname,
FH => $sentfile
);
Also note that the above sets the attachment type according the the information provided by the browser, though be aware that you may get weird results when certain MIME types use the same extensions. For example, I uploaded a stylesheet during testing and it was described as a Comet Systems Cursor in the email message. Your mileage may vary.
During development, I enabled a Debug flag to help me troubleshoot problems. This resulted in a second attachment containing information I thought relevant at the time. For example:
if ( defined( $settings{ "DEBUG" } ) )
{
$msg->attach
( Type => 'TEXT',
Encoding => 'base64',
Filename => 'debug.txt',
Disposition => 'attachment',
Data => [ "Upload info\n\n",
"File size = $sentsize\n",
( map { "$_ = $sentinfo->{ $_ }\n" } sort keys %$se
+ntinfo ),
"\n",
"ENV Contents:\n\n",
( map { "$_ = $ENV{ $_ }\n" } sort keys %ENV ),
"\n",
"Configuration Settings:\n\n",
( map { "$_ = $settings{ $_ }\n" } sort keys %setti
+ngs )
]
);
}
my $cgi = new CGI;
my $sentfile = $cgi->upload( 'sentfile' );
my $sentsize;
my $sentinfo;
my $sentname;
if ( $sentfile )
{
$sentsize = -s ( $sentfile ); # file size
$sentinfo = $cgi->uploadInfo( $sentfile ) ;
fileparse_set_fstype( "MSDOS" ); # risky assumption?
my ( $sentname ) = fileparse( $sentfile );
}
It's not perfect by any means, but it worked well and was a reasonably easy job--once I had merlyn's starting point.
In short, merlyn's article is very helpful, but you'll want to read the MIME::Lite docs pretty carefully and to experiment with the article's code to see how it works on your system.
Also, there are several other threads in the archives that offer alternative approaches and other information.
--f
|