Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Email::Mime send multiple attachments

by Appy16 (Sexton)
on Mar 15, 2010 at 10:42 UTC ( #828657=perlquestion: print w/replies, xml ) Need Help??

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

I've a script through which i'm trying to send multiple attachments. But the problem is that only a single attachment is being sent.I've tried other methods like MIME::Lite and Net::SMTP, but they are not much helpful as they send the Email into the SPAM/JUNK folder.I am posting my script below kindly help me out. thanx in advance.
#!/usr/bin/perl use strict; use warnings; use LWP::Simple; use Email::Send; use Email::Send::Gmail; use Email::MIME::Creator; use IO::All; my $url = "http://abcd.com/search?q=%22MB%22&t=blogs&f=csv"; my $file = "/Users/Abc/Desktop/MB.csv"; my $status = mirror($url,$file); die "Cannot retrieve $url" unless is_success($status); my $url1 = "http://abcd.com/search?q=%22M%22&t=microblogs&f=csv"; my $file1 = "/Users/Abc/Desktop/M.csv"; my $status1 = mirror($url1,$file1); die "Cannot retrieve $url" unless is_success($status1); my $email = Email::MIME->create( header => [ From => 'abcd@gmail.com', To => 'abc1@gmail.com', Subject => 'ABCD', ], attributes => [ { filename =>"MB.csv", content_type =>"application/csv", disposition =>"attachment", Name =>"/Users/Abc/Desktop/MB.csv", }, body => io( "/Users/Abc/Desktop/MB.csv" )->all, { filename =>"M.csv", content_type =>"application/csv", disposition =>"attachment", Name =>"/Users/ab/Desktop/M.csv", }, body => io( "/Users/Abc/Desktop/M.csv" )->all, ], ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => 'abcd@gmail.com', password => '1234qwerty', ] } ); eval { $sender->send($email) }; die "Error sending email: $@" if $@;

Replies are listed 'Best First'.
Re: Email::Mime send multiple attachments
by almut (Canon) on Mar 15, 2010 at 11:28 UTC

    If you look at the synopsis of Email::MIME, you'll see that the structure of a multipart mail looks like this:

    # multipart message my @parts = ( Email::MIME->create( attributes => { ... }, body => io( ... )->all, ), Email::MIME->create( attributes => { ... }, body => io( ... )->all, ), ); my $email = Email::MIME->create( header => [ ... ], parts => [ @parts ], );

    In other words, you cannot simply stick all your body parts in attributes (which needs to be a hashref, btw, not arrayref, as you have it!).  Rather, create individual parts, and stick them in parts => [ ... ].

    P.S.: please use an identation that reflects the logical nesting of things...

Re: Email::Mime send multiple attachments
by Anonymous Monk on Mar 15, 2010 at 11:30 UTC
    You seem to be using Email::MIME in an undocumented way, I suggest you follow the documentation exactly (see examples t/nested-parts.t and t/multipart.t)

    Also, you need to clean your room better, as the mirroring/IO::All portion of your program doesn't seem to relate to your problem.

Re: Email::Mime send multiple attachments
by jfroebe (Parson) on Mar 15, 2010 at 16:49 UTC

      As far as I've understood from a previous post, the OP's special constraint is that the mail must be sent using Email::Send::Gmail, as the module appears to be the only one that out-of-the-box gets the authentication right, i.e. that the mail won't end up in the recipient's spam folder when the mail is being sent from one gmail account to another.

      You have nothing on Email::Simple other than your module isn't available and/or on CPAN.

        The dbS::Email module is just an example on how you might write a module to send attachments.

        Jason L. Froebe

        Blog, Tech Blog

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2023-05-30 02:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?