Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    41

    Question Unanswered: 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\\$_"
    });
    }
    }

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •