basically done, could use some more testing
authorerickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 30 Aug 2006 19:00:27 +0000 (19:00 +0000)
committererickson <erickson@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 30 Aug 2006 19:00:27 +0000 (19:00 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@5783 dcc99617-32d9-48b4-a31d-7c20da2025e4

Evergreen/src/support-scripts/eg_gen_overdue.pl
Evergreen/src/support-scripts/eg_gen_overdue.sh

index 04fecef..494aba9 100755 (executable)
@@ -17,16 +17,20 @@ use vars qw/$logger $apputils/;
 use Data::Dumper;
 use OpenILS::Const qw/:const/;
 use DateTime;
+use Email::Send;
 use DateTime::Format::ISO8601;
 use OpenSRF::Utils qw/:datetime/;
 use Unicode::Normalize;
 
+
 my $bsconfig = shift || die "usage: $0 <bootstrap_config>\n";
 my @goback = @ARGV;
 @goback = (0) unless @goback;
 osrf_connect($bsconfig);
 my $e = OpenILS::Utils::CStoreEditor->new;
 
+my $smtp = $ENV{EG_OVERDUE_SMTP_HOST};
+my $mail_sender = $ENV{EG_OVERDUE_EMAIL_SENDER};
 
 # ---------------------------------------------------------------
 # Set up the email template
@@ -35,7 +39,7 @@ print "Using email template: $etmpl\n";
 open(F,"$etmpl");
 my @etmpl = <F>;
 close(F);
-my $email_template = "@etmpl";
+my $email_template = join('',@etmpl);
 # ---------------------------------------------------------------
 
 
@@ -387,15 +391,17 @@ sub send_email {
 
        my $r = ($range eq '7day') ? 7 : 14;
 
-       $tmpl =~ s/\${EMAIL_RECIPIENT}/$pemail/o;
-       $tmpl =~ s/\${EMAIL_SENDER}/$org_email/o;
-       $tmpl =~ s/\${EMAIL_REPLY_TO}/$org_email/o;
-   $tmpl =~ s/\${EMAIL_HEADERS}/\n\r\n\r/o;
-   $tmpl =~ s/\${RANGE}/$r/o;
-   $tmpl =~ s/\${DATE}/$day\/$mon\/$year/o;
-   $tmpl =~ s/\${FIRST_NAME}/$fn/o;
-   $tmpl =~ s/\${MIDDLE_NAME}/$mn/o;
-   $tmpl =~ s/\${LAST_NAME}/$ln/o;
+       $tmpl =~ s/\${EMAIL_RECIPIENT}/$pemail/;
+       $tmpl =~ s/\${EMAIL_SENDER}/$mail_sender/;
+       #$tmpl =~ s/\${EMAIL_REPLY_TO}/$org_email/o;
+       $tmpl =~ s/\${EMAIL_REPLY_TO}/$mail_sender/;
+   $tmpl =~ s/\${EMAIL_HEADERS}//;
+
+   $tmpl =~ s/\${RANGE}/$r/;
+   $tmpl =~ s/\${DATE}/$day\/$mon\/$year/;
+   $tmpl =~ s/\${FIRST_NAME}/$fn/;
+   $tmpl =~ s/\${MIDDLE_NAME}/$mn/;
+   $tmpl =~ s/\${LAST_NAME}/$ln/;
 
        my ($itmpl) = $tmpl =~ /\${OVERDUE_ITEMS\[(.*)\]}/ms;
 
@@ -420,7 +426,19 @@ sub send_email {
        $tmpl =~ s/\${ORG_ADDRESS}/$org_addr/o;
        $tmpl =~ s/\${ORG_PHONE}/$org_phone/o;
 
-       warn "EMAIL: $tmpl\n";
+       $logger->debug("OD_notice: sending email to $pemail: $tmpl");
+
+       my $sender = Email::Send->new({mailer => 'SMTP'});
+       $sender->mailer_args([Host => $smtp]);
+
+       my $stat;
+       #my $stat = $sender->send($tmpl);
+       
+       if( $stat and $stat->type eq 'success' ) {
+               $logger->info("OD_notice:   successfully sent overdue email");
+       } else {
+               $logger->warn("OD_notice:   unable to send hold overdue email: ".Dumper($stat));
+       }
 
        $logger->info("OD_notice:   sending email to".$patron_data->[0]->email);
 }
index 11528d9..1f1f449 100755 (executable)
@@ -12,6 +12,11 @@ DATE=$(date +%Y-%m-%d);
 DAY=$(date +%u);
 BSCONFIG="/openils/conf/bootstrap.conf"
 ODDIR="/openils/var/data/overdue";
+#ODDIR="/tmp";
+
+export EG_OVERDUE_EMAIL_TEMPLATE="../extras/overdue_notice_email";
+export EG_OVERDUE_SMTP_HOST="apollo.georgialibraries.org";
+export EG_OVERDUE_EMAIL_SENDER="evergreen@georgialibraries.org";
 
 [ $(whoami) != "opensrf" ] && echo "Must be run as opensrf" && exit 1;
 source /etc/profile;
@@ -20,5 +25,6 @@ ARGS="0"
 [ $DAY == 6 -o $DAY == 7 ] && exit 0; # don't run on saturday or sunday
 if [ $DAY == 1 ]; then ARGS="2 1 0"; fi; # If today is monday, run for sat/sun/mon
 
+echo "RUNNING";
 ./eg_gen_overdue.pl $BSCONFIG $ARGS > "$ODDIR/overdue.$DATE.xml"