Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Email::Mime 1 email + multiple attachments

by Eliya (Vicar)
on May 20, 2012 at 17:13 UTC ( #971504=note: print w/ replies, xml ) Need Help??


in reply to [Resolved]Email::Mime 1 email + multiple attachments

recipient will not receive 1 e-mail with 3 attachments, but 3 e-mails with 1 attachment in each e-mail

That's not too surprising, as your foreach loop is around everything.  Instead, create the list of attachments first, and then create one email to which you pass the list of attachments (@parts). I.e.

... my @parts; foreach (@files) { push @parts, Email::MIME->create( # attachments ... ); } $email = Email::MIME->create( # actual email ... parts => [ @parts ], ... ); ...


Comment on Re: Email::Mime 1 email + multiple attachments
Select or Download Code
Re^2: Email::Mime 1 email + multiple attachments
by kazak (Beadle) on May 20, 2012 at 18:08 UTC
    I've done so before asking, sorry I forgot to mention about this. If I'm trying to access @parts not in "foreach" @parts are empty. Like yesterday:
    ./report_sender.pl Last execution date, not found for: Weekly summary DATE:2012-05-19 TODAY:2012-05-19 NEXT:2012-05-19 report: credentials last executed: 2012-05-19 next scheduled: 2012-05-19 FILENAME:Servers.7z FILENAME:weekly_sites.7z Net::SMTP>>> Net::SMTP(2.31) Net::SMTP>>> Net::Cmd(2.29) Net::SMTP>>> Exporter(5.63) Net::SMTP>>> IO::Socket::INET(1.31) Net::SMTP>>> IO::Socket(1.31) Net::SMTP>>> IO::Handle(1.28) Net::SMTP=GLOB(0x15ff3b0)<<< 220 example.com (mrbap4) Welcome to Zeus +ESMTP server Net::SMTP=GLOB(0x15ff3b0)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x15ff3b0)<<< 250-example.com Net::SMTP=GLOB(0x15ff3b0)<<< 250-STARTTLS Net::SMTP=GLOB(0x15ff3b0)<<< 250-AUTH LOGIN PLAIN Net::SMTP=GLOB(0x15ff3b0)<<< 250-AUTH=LOGIN PLAIN Net::SMTP=GLOB(0x15ff3b0)<<< 250-SIZE 120000000 Net::SMTP=GLOB(0x15ff3b0)<<< 250 HELP Net::SMTP=GLOB(0x15ff3b0)>>> AUTH LOGIN Net::SMTP=GLOB(0x15ff3b0)<<< 334 VXNlcm5hbWU6 Net::SMTP=GLOB(0x15ff3b0)>>> cmVwb3J0ZXJAZGlhbG9nLXdlYmRlc2lnbi5kZQ== Net::SMTP=GLOB(0x15ff3b0)<<< 334 UGFzc3dvcmQ6 Net::SMTP=GLOB(0x15ff3b0)>>> cmVwb3J0ZXJxYXo= Net::SMTP=GLOB(0x15ff3b0)<<< 235 Authentication successful Net::SMTP=GLOB(0x15ff3b0)>>> MAIL FROM:<reporter@example.com > Net::SMTP=GLOB(0x15ff3b0)<<< 250 OK Net::SMTP=GLOB(0x15ff3b0)>>> RCPT TO:<dummy72@gmail.com> Net::SMTP=GLOB(0x15ff3b0)<<< 250 OK Net::SMTP=GLOB(0x15ff3b0)>>> DATA Net::SMTP=GLOB(0x15ff3b0)<<< 354 Enter mail, end with "." on a line by + itself Net::SMTP=GLOB(0x15ff3b0)>>> To: user@example.com Net::SMTP=GLOB(0x15ff3b0)>>> From: reporter@example.com Net::SMTP=GLOB(0x15ff3b0)>>> Subject: credentials Net::SMTP=GLOB(0x15ff3b0)>>> Date: Sat, 19 May 2012 19:26:23 +0200 Net::SMTP=GLOB(0x15ff3b0)>>> MIME-Version: 1.0 Net::SMTP=GLOB(0x15ff3b0)>>> Content-Disposition: inline Net::SMTP=GLOB(0x15ff3b0)>>> Content-Type: text/plain; charset="us-asc +ii" Net::SMTP=GLOB(0x15ff3b0)>>> . Net::SMTP=GLOB(0x15ff3b0)<<< 250 Message 0LiUtY-1Rw1Ew1QTc-00crW0 acce +pted by example.com Net::SMTP=GLOB(0x15ff3b0)>>> QUIT Net::SMTP=GLOB(0x15ff3b0)<<< 221 OK
      If I'm trying to access @parts not in "foreach" @parts are empty.

      You don't show the updated code, but my guess would be that you still have my @parts = ... within the foreach loop (like in your OP), instead of declaring the @parts array outside of the loop (like in the code I outlined).

      If you declare it within the loop, it's lexically scoped to the loop, i.e. not accessible outside of it.  Also, you'd create a new array instance on every iteration, instead of accumulating stuff in it.

      Sorry Eliya, this was my bad. It's true that I tried to use "@parts" outside foreach, BUT I used "@parts =" instead of "push" and this was main problem. You were absolutely right when you wrote your reply to me. Thank you very much.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (15)
As of 2014-09-22 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls