Last active
June 2, 2016 12:34
-
-
Save johnalvero/68649026d3a4b741c8c0858bc92f585b to your computer and use it in GitHub Desktop.
SES
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# John Homer Alvero | |
# May 2016 | |
# SESsender.pl | |
# | |
# Usage: cat input.csv | ./SESsender.ph | |
use MIME::Entity; | |
use Net::AWS::SES; | |
my $ses = Net::AWS::SES->new(access_key => 'AKIA...', secret_key => '...'); | |
while (<>) { | |
# Parse input | |
my @line = split(','); | |
my $username = $line[5]; | |
my $password = $line[6]; | |
my $email = $line[3]; | |
# Skip the header line | |
next if ($username eq "User"); | |
# Setup the Mime object | |
$msg = MIME::Entity->build( | |
From => 'John Homer Alvero <[email protected]>', | |
To => "$email", | |
Subject => 'Sample Subject', | |
Data => "<html><body>Hello from SES</body></html>", | |
Type => 'text/html' | |
); | |
$msg->attach( | |
Path => File::Spec->catfile( '/path/to/file.pdf' ), | |
Type => 'application/pdf', | |
Encoding => 'base64' | |
); | |
# Send the message | |
$r = $ses->send($msg); | |
if ( $r->is_success ) { | |
print "Mail sent to $email\n"; | |
} else { | |
die $r->error_message; | |
} | |
# Wait so that we don't hit the SES sending limitation | |
sleep(2); | |
} | |
print "Done\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment