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

I have a CGI written in perl, using the MIME::Lite module. It works fine at submitting emails, but when I try attaching files, and then sending it, it just hangs. It also causes quite a bit of load.

$FileEmail = MIME::Lite->new(%Email);
$FileEmail->attach(
	Type     => "application/octet-stream",
	Path     => "/file.exe",
        Filename => "File.exe"
);
$Results = $FileEmail->send();

^^ The email hash contains all the normal email information, and without the file attachments works fine.

Anyone else have this problem?

Title edit by tye

  • Comment on MIME::Lite in CGI hangs if there are attachments

Replies are listed 'Best First'.
Re: MIME::Lite
by tachyon (Chancellor) on Dec 21, 2002 at 05:20 UTC

    Your syntax is wrong (well sort of). You need

    $FileEmail->attach( Type => "application/octet-stream", Path => "/file.exe", Filename => "File.exe" Disposition => 'attachment' );

    You are missing the Disposition key which may fix the problem as without it you rely on the attach to single part hack. You can check what is bing sent with print $FileEmail->as_string - you should see what looks like an normal email with boundaries and the base 64 encoded file. If you don't then you probably have a permissions or a path problem so add a debugging line or two to try to open the file from the script - if this fails you have isolated your problem. Do you really have a file called file.exe in your / (root) directory? You need a full valid path to the file and your script (running as user nobody/apache/etc) must have read permission on it. Don't try to use relative paths if you want to avoid pain.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: MIME::Lite
by arrow (Friar) on Dec 21, 2002 at 01:58 UTC
    Did you try attaching a simple text file? MIME::Lite might not be able to handle "application/octect-stream". Other than that, your syntax look okay (but I've always been bad at spotting syntax errors 8^)

    Just Another Perl Wannabe
      MIME::Lite might not be able to handle "application/octect-stream"

      From the docs:

      application
      Data which does not fit in any of the other categories, particularly data to be processed by some type of application program. application/octet-stream, application/gzip, application/postscript...

      --

        oops, thanks cjf-II, didn't see that when I read the docs. Thanks... Just Another Perl Wannabe
Re: MIME::Lite
by benn (Vicar) on Dec 21, 2002 at 01:59 UTC
    Only a thought, and your code snippet is probably just an example, but does '/file.exe' exist? In your root dir? Maybe './file.exe'? Try checking the return value of attach(). Best o'luck.