/
email_snds_data
executable file
·55 lines (41 loc) · 1 KB
/
email_snds_data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
use strict;
use warnings;
use 5.010;
use LWP::UserAgent;
use Email::Stuffer;
my $to = shift || die "No email address given\n";
my @urls = qw[
https://postmaster.live.com/snds/data.aspx
https://postmaster.live.com/snds/ipStatus.aspx
];
my $key = shift || $ENV{SNDS_KEY};
die "No SNDS key given\n" unless defined $key;
my $ua = LWP::UserAgent->new;
my $email = Email::Stuffer->new
->to($to)
->subject('SDNS Data')
->from('postmaster@mag-sol.com');
my $body = 'Here is your SNDS data';
foreach (@urls) {
if (my $file = get_url($ua, $_, $key)) {
$email->attach_file($file);
} else {
$body .= "\n\nNo data from $_.";
}
}
$email->text_body($body);
$email->send_or_die;
sub get_url {
my ($ua, $url, $key) = @_;
my $resp = $ua->get("$url?key=$key");
my $data = $resp->content;
unless (length $data) {
warn "No data from $url\n";
return;
}
my $file = $resp->filename;
open my $out_fh, '>', $file or die "$file: $!";
print $out_fh $data;
return $file;
}