Superbroom2.0 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to grab variables from a license file, then grab all of those values and place them into a single email with the information listed as such: $keyname $keyexpr $keycount $keyavailable $keyname $keyexpr $keycount $keyavailable $keyname $keyexpr $keycount $keyavailable...etc. When I do this with the existing code it sends the correct data, but only one line per email. What am I doing wrong, and is there a better way to do this?

### RETRIEVE LICENSE DETAILS ######################################### +########## my @keylist = (); # Application returned license list (limited to Ar +rayMax elements) # call APP SOAP APP_SystemKeys method with required parameters my $vpsxkeylist = $soap->VPSX_SystemKeys( SOAP::Data->type('string')->name('SessID')->value($session +ID), SOAP::Data->type('string')->name('VPSID')->value($vpsx), ); # catch errors if ( $appkeylist->fault ) { print "\t* ERROR RETRIEVING VPSX KEYS: INVALID VPSX_SystemKeys + PARAMETERS\n\n"; if ($log ne "") { $datestring = localtime(); print LOGFILE "* ERROR RETRIEVING APP KEYS: INVALID APP_Sy +stemKeys PARAMETERS\n"; print LOGFILE "$datestring\n"; } exit(4); } else { print "\n\tPRODUCT EXPIRATION T +OTAL AVAILABLE\n\n" if (!$hidestdout); print LOGFILE "\t\tPRODUCT EXPIR +ATION TOTAL AVAILABLE\n" if ($log ne ""); @keylist = @{ $appkeylist->result }; foreach my $key (@keylist) { my $keyname = $key->{Name}; my $keyexpr = $key->{Expiration}; my $keycount = $key->{Count}; my $keyavailable = $key->{Available}; if ($keycount == "-1") {$keycount = "UNLIMITED"}; if ($keyavailable == "-1") {$keyavailable = "UNLIMITED +"}; $keyname = sprintf("%-32s", $keyname); $keyexpr = substr($keyexpr,0,10); $keycount = sprintf("%-9s", $keycount); $keyavailable = sprintf("%-9s", $keyavailable); print "\t$keyname $keyexpr $keycount $keyavailable\ +n" if (!$hidestdout); print LOGFILE "\t\t$keyname $keyexpr $keycount $key +available\n" if ($log ne ""); if ($debug and !$hidestdout) { $smtp = Net::SMTP->new($mailhost, Debug => 1); } else { $smtp = Net::SMTP->new($mailhost); } eval { $smtp->mail($mailfrom) || die("$!\n"); if ($smtp->to(split(/,/, $mailto))) { $smtp->data(); $smtp->datasend("Subject: License File Sta +tus Report\n"); $smtp->datasend("\n"); + $smtp->datasend("\t \n"); $smtp->dataend(); } else { print "\tERROR SENDING EMAIL, RUN WITH DEB +UG FOR MORE INFO: ", $smtp->message(); print "\tCHECK MAIL KEYWORDS: mailhost=$ma +ilhost | mailfrom=$mailfrom | mailto=$mailto\n\n"; print LOGFILE "ERROR SENDING EMAIL, RUN WI +TH DEBUG FOR MORE INFO: ", $smtp->message() if ($log ne ""); print LOGFILE " RUN WITH DEBUG, CHECK MAI +L KEYWORDS: mailhost=$mailhost | mailfrom=$mailfrom | mailto=$mailto\ +n" if ($log ne ""); } }; if ($@) { print "\tERROR SENDING EMAIL, RUN WITH DEBUG F +OR MORE INFO\n"; print "\tCHECK MAIL KEYWORDS: mailhost=$mailho +st | mailfrom=$mailfrom | mailto=$mailto\n\n"; print LOGFILE "ERROR SENDING EMAIL, RUN WITH D +EBUG FOR MORE INFO\n" if ($log ne ""); print LOGFILE " CHECK MAIL KEYWORDS: mailhost +=$mailhost | mailfrom=$mailfrom | mailto=$mailto\n" if ($log ne ""); } } $smtp->quit; }

Replies are listed 'Best First'.
Re: Sending an email of compiled data
by hippo (Archbishop) on Feb 06, 2017 at 18:53 UTC

    You are sending the email inside the foreach loop so naturally each email sent will only contain one record. Build up your message text inside the foreach loop, appending each time and then do your mail sending once the foreach loop has ended.

      I was able to get this to work by concatenating each variable into another variable, then using that second variable as the "message body" of the email. Thank you for your help!

      $mail_body .= "\t$keyname $keyexpr $keycount $keyavailable\n"; ... $smtp->datasend("\t $mail_body \n");