Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

MIME::Lite not including Attachments

by guitarplayer68 (Novice)
on Feb 09, 2010 at 15:11 UTC ( [id://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 => 'me@myhost.com', To => 'you@yourhost.com', Cc => 'some@other.com, some@more.com', 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','some.host', Debug=>1 );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://822208]
Approved by marto
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-20 01:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found