Skip to content

Commit

Permalink
Add email utility
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Feb 2, 2016
1 parent 76fedd6 commit d878aa3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -9,3 +9,4 @@ Utilities
---------

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.
51 changes: 51 additions & 0 deletions email_snds_data
@@ -0,0 +1,51 @@
#!/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')
->text_body('Here is your SNDS data');

foreach (@urls) {
if (my $file = get_url($ua, $_, $key)) {
$email->attach_file($file);
}
}

$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 for $url\n";
return;
}

my $file = $resp->filename;
open my $out_fh, '>', $file or die "$file: $!";
print $out_fh $data;

return $file;
}

0 comments on commit d878aa3

Please sign in to comment.