On Thu, Jun 25, 2009 at 4:05 AM, Serguei Trouchelle<[email protected]> wrote:
> Chris Marshall wrote:
>
>> I'm trying to use Test::Reporter with Net::SMTP::TLS
>> and having no luck.  If someone has gotten this to
>> work (especially with gmail smtp), I would appreciate
>> the working template for use.
>
> Here's a script I'm using to send reports via google.
>
> I'm using "transport=File" to store reports in directory and run this script
> from it once a day, because gmail accepts only 500 messages to one recipient
> per day, and smokers often go over the limit.
>
That is exactly what I do, only I do it with about 15 different email
addresses and I randomly switch between them, removing them from the
rotation if I get an error. While I acknowledge that the sort
{rand<.5} is poor practice, I don't care because this way was easier
at the time. This way I can run two or three or thirty of these and
they'll all not try to get the same report at the same time.

use Test::Reporter;

opendir(DIR, '/usr/share/reports');
@reports = grep { /^[^.]/ && -f "/usr/share/reports/$_" } readdir(DIR);
closedir DIR;

@addresses=("589", "5100", "5100rc1", "smoker1", "smoker2", "smoker3",
"smoker4", "smoker5", "smoker6", "smoker7", "smoker8", "smoker9");

foreach $file (sort {rand() > .5} @reports) {
        unless (-e "/usr/share/reports/$file") {next}
        $addid=int((scalar @addresses)*rand());
        $address=$addresses[$addid];
        $reporter=Test::Reporter->new();
        $reporter->transport('Net::SMTP::TLS');
        $reporter->transport_args(Host => 'smtp.gmail.com', User =>
"CPAN.DCOLLINS.$address", Password => 'passwordhere');
        print "$file\n";
        print "$addid:$address\n";
        `perl -i -p -e 's|[email protected]|[email protected]|g'
/usr/share/reports/$file`;
        eval('$report=$reporter->read("/usr/share/reports/$file")');
        $error=$reporter->errstr();
        $error ? print $error."\n" && next : undef;
        `rm -f /usr/share/reports/$file`;
        eval('$retval=$report->send()');
        $error=$reporter->errstr();
        $error ? (print $error."\n") && (delete $addresses[$addid]) &&
((@addresses=grep {$_} @addresses) || die) : undef;
}


-- 
DCollins/ST47

Reply via email to