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

Using the following code I'm able to send files, but when I send an excel file it comes out the other in the right size, but excel fails to open it. I'm betting this is something obvious, but any help is appreciated. BTW This is a command line script, i just use CGI to handle command line parameters because i'm lazy and it works.

use strict; use warnings; use MIME::Lite; use CGI; my $cgi = new CGI; MIME::Lite->send('smtp', '192.168.11.203', Timeout=>60); my $to = $cgi->param("to"); my $from = $cgi->param("from"); my $subject = $cgi->param("subject"); my $text = $cgi->param("text"); my @files = ($cgi->param("files")); my $msg = MIME::Lite->new( To => $to, From => $from, Subject => $subject, Type => 'multipart/mixed', ); $msg->attach(Type => 'TEXT', Data => $text ); for my $file (@files) { $msg->attach(Id => $file, Path => $file ); } $msg->send; ### will now use Net::SMTP as shown above

___________
Eric Hodges

Replies are listed 'Best First'.
Re: Sending Email Attachment
by philcrow (Priest) on Feb 19, 2007 at 17:32 UTC
    Try an attachment type change from TEXT to 'application/vnd.ms-excel'.

    Phil

      Okay that worked perfectly. Is there a type I can use that will work no matter what type of file it is?


      ___________
      Eric Hodges

        No, that's the whole point of MIME types: to identify the format of the data in the file so the receiving tool can decide to handle it or pass it off.

        You might want to use File::MimeInfo or the 'file' command on unix to identify the appropriate MIME type for a file.

        --
        Clayton
Re: Sending Email Attachment
by j3 (Friar) on Feb 19, 2007 at 17:44 UTC

    (Edit: Whoops, sorry, not useful.)