Advertisement
Guest User

Untitled

a guest
Sep 17th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #Get clubs from DB and email out the bounces to the secretaries.
  2. #I'm sorry to myself and anyone who has to use this... (06/09/13 - DJC)
  3.  
  4. use DBI;
  5. use Data::Dumper;
  6. use Email::MIME;
  7.  
  8. [redacted DB details]
  9.  
  10. #Connect to the DB
  11. $dbh = DBI->connect('dbi:mysql:'.$db,$user,$pass) or die "Connection Error: $DBI::errstr\n";
  12.  
  13. $sql = "SELECT ClubNo FROM Bounces Group By ClubNo";
  14. $sql_sth = $dbh->prepare($sql);
  15. $sql_sth->execute();
  16.  
  17. #This is a bit horrible...
  18.  
  19. while(my ($ClubID) = $sql_sth->fetchrow_array()) {
  20. #print "Club: $ClubID\n";
  21. my $sql2 = "SELECT Rotarians.MemEmail FROM clubofficeholders JOIN Rotarians ON Rotarians.RotID = clubofficeholders.RotID WHERE clubofficeholders.ClubID=$ClubID AND clubofficeholders.YrID=109 AND clubofficeholders.ClubOffID IN (1,2)";
  22. $sql2_sth = $dbh->prepare($sql2);
  23. $sql2_sth->execute() or die "SQL Error: $DBI::errstr";
  24.  
  25. my @Emails;
  26. my @Members;
  27.  
  28. #Secretary's email address
  29. while(my ($MemEmail) = $sql2_sth->fetchrow_array()){
  30. print " Club: $ClubID AND EMAIL: $MemEmail\n";
  31. push(@Emails, $MemEmail);
  32.  
  33. }
  34.  
  35.  
  36. #print "Sec: ".$sec_email."\n";
  37. #print Dumper(@Emails);
  38.  
  39.  
  40. #Why are we doing it this way? Really? I hope an actual programmer never sees this...
  41. my $sql3 = "SELECT EmailAddress FROM Bounces WHERE ClubNo=$ClubID";
  42. $sql3_sth = $dbh->prepare($sql3);
  43. $sql3_sth->execute() or die "SQL Error: $DBI::errstr";
  44.  
  45. #eq not == for some strange reason (Perl...)
  46. #print "\n";
  47. while(my ($EmailAddress) = $sql3_sth->fetchrow_array())
  48. {
  49.  
  50. if ( grep( /^$EmailAddress$/, @Members ) )
  51. {
  52. #print "exists";
  53. }
  54. else
  55. {
  56. #print "Member: ".$EmailAddress."\n";
  57. #This bit is the actaul members email address that's bouncing
  58. push(@Members, $EmailAddress);
  59. }
  60. $EmailSend = $Emails[1];
  61.  
  62. }
  63.  
  64. Dumper($Emails[1]);
  65.  
  66. #$Emails[1];
  67.  
  68. if ($EmailSend eq "")
  69. {
  70. $EmailSend = "postmaster\@rotary-ribi.org";
  71. }
  72.  
  73. #print $EmailSend;
  74.  
  75. if ($Emails[1] eq "")
  76. {
  77. $Emails[1] = "postmaster\@rotary-ribi.org";
  78. }
  79.  
  80. $email_body_1 = "The following member's emails are bouncing back to the Rotary Email Server. This is a result of their email addresses being incorrect or a spam filter blocking Rotary emails. AOL and Hotmail are often culprits for being overzealous with their blocking.
  81.  
  82. Please correct the member's database record or contact the relevant Rotarian to advise them to add rotary-ribi.org to their whitelist or use another email address for Rotary";
  83.  
  84. $email_body_2 = join(', ', @Members);
  85. $email_body_2 = join "\n", split ", ", $email_body_2;
  86.  
  87. $email_body = $email_body_1 . $email_body_2;
  88.  
  89. #Time to actually send it, yay!
  90.  
  91. my $message = Email::MIME->create(
  92. header_str => [
  93. From => 'postmaster@rotary-ribi.org',
  94. To => '$Emails[1]',
  95. Subject => 'Rotary Email Bounces',
  96. ],
  97. attributes => {
  98. encoding => 'quoted-printable',
  99. charset => 'ISO-8859-1',
  100. },
  101. body_str => "$email_body",
  102. );
  103.  
  104. # send the message
  105. use Email::Sender::Simple qw(sendmail);
  106. sendmail($message);
  107. print "Sent to $Emails[1] \n";
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement