Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # John Homer Alvero
  4. # May 2016
  5. # SESsender.pl
  6. #
  7. # Usage: cat input.csv | ./SESsender.ph
  8.  
  9. use MIME::Entity;
  10. use Net::AWS::SES;
  11. my $ses = Net::AWS::SES->new(access_key => 'AKIA...', secret_key => '...');
  12.  
  13. while (<>) {
  14. # Parse input
  15. my @line = split(',');
  16.  
  17. my $username = $line[5];
  18. my $password = $line[6];
  19. my $email = $line[3];
  20.  
  21. # Skip the header line
  22. next if ($username eq "User");
  23.  
  24. # Setup the Mime object
  25. $msg = MIME::Entity->build(
  26. From => 'John Homer Alvero <john@voyager.ph>',
  27. To => "$email",
  28. Subject => 'Sample Subject',
  29. Data => "<html><body>Hello from SES</body></html>",
  30. Type => 'text/html'
  31. );
  32.  
  33. $msg->attach(
  34. Path => File::Spec->catfile( '/path/to/file.pdf' ),
  35. Type => 'application/pdf',
  36. Encoding => 'base64'
  37. );
  38.  
  39. # Send the message
  40. $r = $ses->send($msg);
  41.  
  42. if ( $r->is_success ) {
  43. print "Mail sent to $email\n";
  44. } else {
  45. die $r->error_message;
  46. }
  47.  
  48. # Wait so that we don't hit the SES sending limitation
  49. sleep(2);
  50. }
  51.  
  52. print "Done\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement