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

Does anyone know how I can send the contents of an array using Net::SMTP for instance:
$smtp = Net::SMTP->new('Mail.Server'); $smtp->mail( 'user.com' ); $smtp->to($emailid); $smtp->data(); # Start the mail $smtp->datasend("To: Mickey Mouse\n"); $smtp->datasend("From: John Doe\n"); $smtp->datasend("\n"); $smtp->datasend(@LogFile); $smtp->dataend(); # Finish sending the mail $smtp->quit; # Close the SMTP connection
@LogFile is the array I'm using Thanks for the help!

Replies are listed 'Best First'.
Re: Net::SMTP and arrays
by vladb (Vicar) on May 31, 2002 at 13:19 UTC
    You can always simply join every element of the array to produce a large text string and save it into a scalar variable. So, the code might look as follows
    $smtp = Net::SMTP->new('Mail.Server'); $smtp->mail( 'user.com' ); $smtp->to($emailid); $smtp->data(); # Start the mail $smtp->datasend("To: Mickey Mouse\n"); $smtp->datasend("From: John Doe\n"); $smtp->datasend("\n"); my $log_data = "Log File Contents:\n" . join("\n", @LogFile); $smtp->datasend($log_data); $smtp->dataend(); # Finish sending the mail $smtp->quit; # Close the SMTP connection


    _____________________
    $"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}
Re: Net::SMTP and arrays
by Steve_p (Priest) on May 31, 2002 at 13:35 UTC
    You could alway try
    foreach $logLine (@LogFile) { $smtp->datasend($logLine); }
Re: Net::SMTP and arrays
by Hofmator (Curate) on May 31, 2002 at 13:50 UTC
    If it's a file, did you think of simply attatching it to the mail?

    -- Hofmator

      Yes, but is that possible with Net::SMTP?
        Well it is possible to do with Net::SMTP, but really difficult because you have to handle all the MIME encoding yourself.

        I would suggest taking a look at MIME::Lite which allows you to send individual files as well as attach files to text messages. I think this will work well for what you are trying to do.

        -----------------------------------
        Frank Wiles <frank@wiles.org>
        http://frank.wiles.org