If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > Email attachments using PERL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-06, 19:19
gauravjain21 gauravjain21 is offline
Registered User
 
Join Date: Mar 2005
Posts: 41
Question Email attachments using PERL

I have a PERL script that reads and writes to a excel file in UNIX. After writing to the excel file, it saves a copy in one of the sub directories called 'Output'.

I need help in sending the contents of this Output folder as an atachment to a particular user in a form of an email.

Following is a part of the script:

use Net:MTP;
use Mail:ender;
my $sender;

opendir DIRH, "output" or die "couldn't open: $!";

foreach (sort readdir DIRH)
{
print ("$_ \n");
if ($_ =~ /xls$/) {

$sender = new Mail:ender {smtp => 'mailhost.company.com', from => 'Auto Excel <first_name.last_name@company.com>'};
$sender ->MailFile({to => 'recipent.dude@company.com',
subject => 'Auto Excel Results',
msg => "\nThe latest results have been run.\n\nResults are attached.",
file => "output\\$_"
});
}
}
Reply With Quote
  #2 (permalink)  
Old 02-02-06, 23:34
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
Do you want "one attachment" that contains all Excel files from the subdirectory??
Then you should use Archive::Zip and archive all the files and attach it.

Do you want all files attached to _one_ email??
You should not create a new Mail:ender-object each iteration!

Code:
use Net::SMTP;
use Mail::Sender;

my $sender = new Mail::Sender {
     smtp => 'mailhost.company.com', 
     from => 'Auto Excel <first_name.last_name@company.com>',
     to => 'recipent.dude@company.com',
     subject => 'Auto Excel Results',
     msg => "\nThe latest results have been run.\n\nResults are attached."};

opendir DIRH, "output" or die "couldn't open: $!";
my @excels = grep{/\.xls$/}readdir(DIRH);
closedir DIRH;

$sender->Attach($_) for(@excels);
__________________
board.perl-community.de - The German Perl-Community
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On