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

Is it possible to attatch a file to an email using a Perl script? If so, I would appreciate it if someone could tell me how. Thanks.

Replies are listed 'Best First'.
Re: Attach a file to email
by fundflow (Chaplain) on Jul 25, 2000 at 19:06 UTC
Re: Attach a file to email
by tiny (Beadle) on Jul 26, 2000 at 00:06 UTC
    MIME::Lite makes this very easy:
    use MIME::Lite; my $msg = MIME::Lite->new ( From => 'you@somewhere.com', To => 'someone@somewhere.com', Subject => 'A subject line', Type => 'multipart/mixed'); $msg->attach( Type => 'TEXT', Data => 'Normal text of the email' ); # open a file to send open FILE "file.zip"; my $data = <FILE>; close FILE; $msg->attach( Type => 'BINARY', # or any MIME type you like Data => '$data', Filename => 'file.zip' ); $msg->send;
    This link to CPAN will give you lots more info, too.
      Ok. But there's a little problem here. Try to send to an HTML account. I can't. I have tried hard with many smtp servers but nothing. Why?? I can't send it by hand (telnet), too!!! The server accepts the mail but I never receive it. The script hangs and stays when you try to send to a hotmail account... Isn't it couriuos???!!!!