#!/usr/bin/perl
-e
"$Bin/gmail_account.txt"
or
die
"Can't send the report, please create gmail_account.txt\n"
;
-e
"$Bin/test_accounts.txt"
or
die
"No test accounts since no test_accounts.txt\n"
;
my
$is_broken
= 0;
my
$body
=
"Test WWW::Contact $WWW::Contact::VERSION\n\n"
;
my
$wc
= new WWW::Contact;
open
(
my
$fh
,
'<'
,
"$Bin/test_accounts.txt"
) or
die
$!;
local
$/;
my
$test_accounts
= <
$fh
>;
close
(
$fh
);
my
@lines
=
split
(/\r?\n/,
$test_accounts
);
foreach
my
$line
(
@lines
) {
my
(
$email
,
$pass
) = (
$line
=~ /(\S+)\s+(\S+)/ );
my
@contacts
=
$wc
->get_contacts(
$email
,
$pass
);
my
$errstr
=
$wc
->errstr;
if
(
$errstr
or
scalar
@contacts
== 0 ) {
$body
.=
"$email is broken I guess, please check it manually.\n\n"
;
$is_broken
= 1;
}
else
{
$body
.=
"$email [OK]\n\n"
;
}
}
if
(
$is_broken
) {
print
STDERR
$body
;
open
(
my
$fh2
,
'<'
,
"$Bin/gmail_account.txt"
);
my
$mail_info
= <
$fh2
>;
close
(
$fh2
);
my
(
$email
,
$pass
) = (
$mail_info
=~ /(\S+)\s+(\S+)/ );
my
$mailer
= Email::Send->new( {
mailer
=>
'SMTP::TLS'
,
mailer_args
=> [
Host
=>
'smtp.gmail.com'
,
Port
=> 587,
User
=>
$email
,
Password
=>
$pass
,
Hello
=>
'fayland.org'
,
]
} );
my
$es
= Email::Simple->create(
header
=> [
From
=>
$email
,
To
=>
'perl-www-contact@googlegroups.com'
,
Subject
=>
"Report on WWW-Contact $WWW::Contact::VERSION "
.
scalar
(
localtime
()),
],
body
=>
$body
,
);
eval
{
$mailer
->
send
(
$es
) };
die
"Error sending email: $@"
if
$@;
}
1;