diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afed073 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.csv diff --git a/README.md b/README.md index e95f991..f4c3d0b 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,5 @@ See https://postmaster.live.com/snds/ for details. Utilities --------- -get_ms_data - Gets the two current data files for your SNDS account. +* get_snds_data - Gets the two current data files for your SNDS account. +* email_snds_data - Get the data files and send them to an email address. diff --git a/email_snds_data b/email_snds_data new file mode 100755 index 0000000..6d733b4 --- /dev/null +++ b/email_snds_data @@ -0,0 +1,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; +} diff --git a/get_ms_data b/get_snds_data similarity index 100% rename from get_ms_data rename to get_snds_data