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 ], ... ); ...

Replies are listed 'Best First'.
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:
    ./ 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 (mrbap4) Welcome to Zeus +ESMTP server Net::SMTP=GLOB(0x15ff3b0)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x15ff3b0)<<< 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:< > Net::SMTP=GLOB(0x15ff3b0)<<< 250 OK Net::SMTP=GLOB(0x15ff3b0)>>> RCPT TO:<> 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: Net::SMTP=GLOB(0x15ff3b0)>>> From: 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 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.