Hi, to all.
I'm trying to add multiple attachments with Email::Mime to 1 email. Script executed by schedule and checks MySQL DB in order to get recipients list, attachment list, etc. I managed to implement my idea but not like I wanted. (For each recipient script compiles his own e-mail and attaches 1 file, in result 1 recipient will not receive 1 e-mail with 3 attachments, but 3 e-mails with 1 attachment in each e-mail.) The main problem for me is: If I'm trying to access "@parts" outside of "foreach loop", @parts are empty, so I definitely doing something wrong, but I can't find where, thanks in advance.
Here is the piece of code and attachment list format:
Attachment list may look like this: summary.csv,weekly.csv,john.csv
my @files = split /,/,$Attachment;
foreach (@files) {
chomp;
my $f_name = $_;
$f_name =~ s/\/root\/Helpers/reports\///;
print "FILENAME:$f_name\n";
my @parts = (
Email::MIME->create(
attributes => {
filename => "$f_name",
content_type => "application/x-7z-compressed",
disposition => "attachment",
encoding => "base64",
name => "$f_name",
},
body => io( $_ )->all,
),
);
$email = Email::MIME->create(
header_str => [ From => 'reporter@example.com' ],
parts => [ @parts ],
header_str => [ To => $To ],
header_str => [ Subject => $Report_name ],
);
$email->filname_set($f_name);
$email->name_set($f_name);
my $eml = $email->as_string;
}