Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

MIME::Lite not including Attachments

by guitarplayer68 (Novice)
on Feb 09, 2010 at 15:11 UTC ( #822208=perlquestion: print w/replies, xml ) Need Help??
guitarplayer68 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings All,

I am having an issue where mime lite is not including the attachment when it sends out the file. The main part of the script creates the attachment and is quite involved. Simply it creates a tab separated file since some of the data elements contain commas. The script runs and mime lite sends the message but doesn't include the attachment.
Here is the section of my script for MIME::Lite

my $msg = MIME::Lite->new( From => $from, To => $lobmail, Subject => 'DUA '. $lobn .' Ticket Activity Report', Type => 'multipart/alternative', ); $msg->attach ( Type => 'TEXT', Data => "Attached is the ticket activity report for $lobn", ); $msg->attach( Type => 'text/plain', Encoding => 'base64', Path => '/home/eric/tmp/lobreport.tsv', Filename => 'LobReport.tsv', Disposition => 'attachment' ) or die "Unable to add attachment: $!\n"; $msg->send();

Replies are listed 'Best First'.
Re: MIME::Lite not including Attachments
by tokpela (Chaplain) on Feb 09, 2010 at 16:24 UTC

    Try a different MIME type:

    Type => 'multipart/related'

Re: MIME::Lite not including Attachments
by hesco (Deacon) on Feb 10, 2010 at 05:49 UTC
    I have successfully used this code for that purpose:

    if(defined($email->{'attachments'}->{'count'})){ $msg = MIME::Lite->new( From => "$email->{'from'}", To => "$row->{'email'}", Subject => "$subject", Type => 'multipart/mixed', ); <snip> if(defined($email->{'attachments'}->{'count'})){ for my $i (1 .. $email->{'attachments'}->{'count'}){ $msg->attach( Type => $email->{'attachments'}->{$i}->{'Content-t +ype'}, Disposition => $email->{'attachments'}->{$i}->{'dispositi +on'}, Path => $email->{'attachments'}->{$i}->{'file-path +'}, Filename => $email->{'attachments'}->{$i}->{'filename' +}, Encoding => 'base64', ); } }
    if( $lal && $lol ) { $life++; }
    if( $insurance->rationing() ) { $people->die(); }
Re: MIME::Lite not including Attachments
by steve (Deacon) on Feb 11, 2010 at 15:57 UTC

    Perhaps you should try using a content type of multipart/mixed.

    The following example is an excerpt from MIME::Lite.

    Create a multipart message (i.e., one with attachments) and send it SMTP
    ### Create a new multipart message: $msg = MIME::Lite->new( From => '', To => '', Cc => ',', Subject => 'A message with 2 parts...', Type => 'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach( Type => 'TEXT', Data => "Here's the GIF file you wanted" ); $msg->attach( Type => 'image/gif', Path => 'aaa000123.gif', Filename => 'logo.gif', Disposition => 'attachment' ); ### use Net:SMTP to do the sending $msg->send('smtp','', Debug=>1 );

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://822208]
Approved by marto
Front-paged by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2018-03-21 05:49 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (263 votes). Check out past polls.