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;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.