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

I am first time using MIME::Lite module. I am getting error by using this code. Please anyone help me how to attach an gif or anyother file using MIME::Lite. Mention what mistake in the below code.

Thanks in advance

use MIME::Lite; ### Start with a simple text message: $msg = MIME::Lite->new( From =>'vijay@india.com', To =>'vijay@yahoo.co.in', Subject =>'A message with 2 parts...', Type =>'TEXT', Data =>"Here's the GIF file you wanted" ); ### Attach a part... the make the message a multipart automaticall +y: $msg->attach(Type =>'image/gif', Path =>'e:\', Filename =>'logo.gif' ); $msg->send();

Regards,

s,,aaagzas3uzttazs444ss12b3a222aaaamkyae,s,,y,azst1-4mky,,d&&print

Replies are listed 'Best First'.
Re: How to send an attachment using MIME::Lite?
by trammell (Priest) on May 17, 2005 at 02:22 UTC
    I'm pretty sure your Path is wrong. From the MIME::Lite docs:
    $msg->attach( Type => "image/gif", Path => "/here/is/the/real/file.GIF", Filename => "logo.gif" );
Re: How to send an attachment using MIME::Lite?
by bradcathey (Prior) on May 17, 2005 at 02:32 UTC

    You are missing the AUTO_CONTENT line, the type should be multipart/mixed, and Dispostion should be 'attachment'. I also use a second attach.

    This is the code I use in production and it works wonders.

    $MIME::Lite::AUTO_CONTENT_TYPE = 1; #-- create the multipart container my $msg = MIME::Lite->new ( From => $query->param('fromwho'), To => $_, Subject => $query->param('subject'), Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; #-- add the text message part $msg->attach ( Type => 'TEXT', Data => $query->param('message'), ) or die "Error adding the text message part: $!\n"; #-- add the ZIP file $msg->attach ( Type => 'AUTO', Path => "../".$file, Filename => $file, Disposition => 'attachment' ) or die "Error adding $file: $!\n"; $msg->send;


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: How to send an attachment using MIME::Lite?
by gube (Parson) on May 17, 2005 at 03:01 UTC

    Hi bradcathey, after your code i change my code no error and prints ok. But not yet seems mail their. please give me any idea.

    #!/usr/bin/perl5.8.0 + use MIME::Lite; + $MIME::Lite::AUTO_CONTENT_TYPE = 1; + ### Start with a simple text message: $msg = MIME::Lite->new( From =>'gubevijay@india.com', To =>'gubevijay@gmail.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed', ) or die "Error creating multipart $! \n"; + # - add the text message part $msg->attach ( Type => 'TEXT', Data => 'hai, how are u', ) or die "Error adding the text message part: $!\n"; ### Attach a part... the make the message a multipart automaticall +y: $msg->attach(Type =>'AUTO', Path =>'/root/logo.gif', Filename =>'logo.gif', Disposition =>'attachment' ) or die "Error adding logo.gif: $!\n"; + + if ($msg->send()) { print "ok"; } else { print "Error sending"; }

    Update: It's working some smtp problem. Thanks bradchatchey