Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Email Multiple Files from Same Directory

by cocl04 (Sexton)
on Jul 20, 2009 at 14:43 UTC ( [id://781640]=perlquestion: print w/replies, xml ) Need Help??

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

All, Does anyone have an example of how to email multiple attachments / files from the same directory to a specified email address. My perl script creates some excel documents in a folder like so...

c:\test_folder\s01.xls

c:\test_folder\s02.xls

c:\test_folder\s03.xls

c:\test_folder\s04.xls

And I would like to send them in one email. Below is the module / code I normally use:

my $sender = new Mail::Sender { smtp => 'email.server', from => 'me@test.com }; $sender->MailFile( { to => 'test@test.com', cc => 'test@test.com', subject => Test Report', msg => "All, The body of the email. Thanks, cocl04 \n", file => 's01.xls', }); $sender->Close;

Is there a way to maybe save the files in an array or hash? What is the best approach? Any help would be greatly appreciated. Thanks, cocl04

Replies are listed 'Best First'.
Re: Email Multiple Files from Same Directory
by Corion (Patriarch) on Jul 20, 2009 at 14:47 UTC

    Looking in the Mail::Sender documentation, I see for the MailFile entry:

    The file parameter may be a "filename", a "list, of, file, names" or a \@list_of_file_names.

    I wonder what problem you encountered with that or how you would phrase it differently to make it more clear how to pass multiple files to the subroutine.

      Failing that, OP could always Tar the files together and just mail that. Might also help if the files are large/numerous?

      Just a something something...

      I can't figure out the syntax for the \@list_of_file_names. I have tried multiple ways. I have tried it with commas and without. I have tried with full directory and with just the file name. Any ideas?

        my @list_of_file_names = ('file1.txt','another_file.doc','/and/this/fi +le.pdf'); $sender->MailFile( { ... file => \@list_of_file_names, }

        or, alternatively

        ... $sender->MailFile({ ... file => ['file1.txt','another_file.doc','/and/this/file.pdf'], })

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-19 22:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found