[Koha] Birthday Wishes email to patron any option from koha?

Alvaro Cornejo cornejo.alvaro at gmail.com
Sat Nov 7 06:04:51 NZDT 2020


Hi

Small bug:

         # Get destination address (private email else professional)
         if ($email) {
            my $to = $email;       <<---------- REMOVE THE my
         } elsif ($emailpro) {
            my $to = $emailpro;          <<---------- REMOVE THE my
         } else {
           next;
         }

Regards,
|----------------------------------------------------------------------------------------|
 Stay safe / Cuídate/  Reste sécurisé
*7* Switch off as you go / Apaga lo que no usas /  Débranchez au fur et à
mesure.
 *q *Recycle always / Recicla siempre / Recyclez toujours
 P Print only if absolutely necessary / Imprime solo si es necesario /
Imprimez seulement si nécessaire


Le jeu. 5 nov. 2020 à 22:21, <pandian at imsc.res.in> a écrit :

> Dear Alvaro,
>
> Thanks very much.  I will check and get back should i need any
> clarifications and help.
>
> Regards,
>
> Pandian
> Quoting Alvaro Cornejo <cornejo.alvaro at gmail.com>:
>
> > Hi
> >
> > Here is the report to setup as *public*:
> >
> > SELECT
> > borrowers.surname, borrowers.firstname, borrowers.email,
> > borrowers.emailpro, borrowers.sex, borrowers.lang
> > FROM borrowers
> > WHERE  DATE_FORMAT(borrowers.dateofbirth, '%m-%d') =
> DATE_FORMAT(CURDATE(),
> > '%m-%d')
> > LIMIT 50
> >
> > You can add other fields to the report so you can do additional
> > verifications/vaidations like the patron is active, has had activity in
> > the last x months/years, etc. Be careful with the order of the fields
> since
> > this will have an impact on the script. We set LIMIT to 50 just to avoid
> > the public report "hard record limit" of 10 records per query. You can
> set
> > it to anything you think is reasonable.
> >
> > The script is what is between ============ lines:
> >
> > The script uses sendmail to send plain text emails. You can modify it to
> > use any of the perl email libraries and use html format instead.
> >
> > koha_birthdays.pl
> > =================
> > #!/usr/bin/perl
> > # Library includes
> >   use strict;
> >   use warnings;
> >   use LWP::UserAgent;
> >   use HTTP::Request;
> >   use JSON;
> >
> >   print "\nEjecutando koha_birthday\n";
> >
> > #My Global Variables
> >   my $hello = "";
> >   my $subject = "";
> >   my $body = "";
> >   my $message = "";
> >   my $to = "";
> >   my $from = "";
> >   my $result = "";
> >   my $i = 0;
> >
> > # Capture report data:
> > # Fields from report: surname firstname email emailpro sex lang
> > # Prepare connection, call url and insert data (json format) to arrary
> >   my $ua = new LWP::UserAgent;
> >   $ua->agent("Perl API Client/1.0");
> >   my $url = "https://YOURSITE/cgi-bin/koha/svc/report?id=XX";  # REPLACE
> > YOUR SITE WITH YOUR OPAC BASE URL and XX WITH THE NUMBER OF THE REPORT
> YOU
> > CREATE ABOVE
> >   my $request = HTTP::Request->new("GET" => $url);
> >   my $response = $ua->request($request);
> >   my $json_obj = JSON->new->utf8->decode($response->content);
> >   my $row_num = scalar(@{$json_obj});
> >
> > #Scroll/split each registry and send the email
> >   foreach my $row (@{$json_obj}) {
> >      if ($i < $row_num) {
> >          my $surname = @{$row}[0];
> >          my $firstname = @{$row}[1];
> >          my $email = @{$row}[2];
> >          my $emailpro = @{$row}[3];
> >          my $sex = @{$row}[4];
> >          my $lang = @{$row}[5];
> >
> >          # Get destination address (private email else professional)
> >          if ($email) {
> >             my $to = $email;
> >          } elsif ($emailpro) {
> >             my $to = $emailpro;
> >          } else {
> >            next;
> >          }
> >
> >          # Assemble the patron salutation string for each language. Our
> > default is es-ES
> >          if ($lang eq "default" || $lang eq "es-ES") {
> >             if ($sex eq "M") {
> >                $hello = "Estimado Sr. $surname,\n"
> >             } elsif ($sex eq "F") {
> >                $hello = "Estimada Sra. $surname,\n"
> >             } else {
> >                $hello = "Estimado(a) $firstname $surname,\n"
> >             }
> >          } elsif ($lang eq "en") {
> >             if ($sex eq "M") {
> >                $hello = "Dear Mr. $surname,\n"
> >         } elsif ($sex eq "F") {
> >                $hello = "Dear Mrs. $surname,\n"
> >             } else {
> >                $hello = "Dear $firstname $surname,\n"
> >             }
> >          }
> >
> >          # Define email subject & body
> >          if ($lang eq "default" || $lang eq "es-ES") {
> >             $subject = "Feliz cumpleaños le desea el CELACP!";
> >             $body = "\n";
> >             $body .= "El CELACP se complace en hacerle llegar sus mejores
> > deseos en esta fecha tan importante para Ud.\n\n";
> >             $body .= "Sinceramente esperamos tenga un muy feliz día y
> > esperamos contar con su presencia en nuestro local\n";
> >             $body .= "o a través de nuestra plataforma virtual en
> > https://biblioteca.celacp.org\n\n";
> >             $body .= "Atentamente,\n\n";
> >             $body .= "Centro de Estudios Latinoaméricanos Antonio Cornejo
> > Polar - CELACP -\n";
> >          } elsif ($lang eq "en") {
> >             $subject = "Happy birthday from the CELACP!";
> >             $body = "\n";
> >             $body .= "The CELACP is pleased to send you its best wishes
> on
> > this important date for you.\n\n";
> >             $body .= "We sincerely hope you have a very happy day and we
> > look forward to seeing you at our library\n";
> >             $body .= "or through our virtual platform at
> > https://biblioteca.celacp.org\n\n";
> >             $body .= "Sincerely,\n\n";
> >             $body .= "Center for Latinamerican Estudies Antonio Cornejo
> > Polar - CELACP -\n";
> >          }
> >
> >          # Final message assembly
> >          #$to = 'dummy at gmail.com'; #Dummy address for testing purposes.
> If
> > uncommented, overrides the destination address and all emails will be
> sent
> > to this address.
> >          $from = 'source_emaiil at mydomain.com';
> >          $message = $hello;
> >          $message .= $body;
> >
> >          # Create mail "session"
> >          open(MAIL, "|/usr/sbin/sendmail -t");
> >
> >          # Email Header
> >          print MAIL "To: $to\n";
> >          print MAIL "From: $from\n";
> >          print MAIL "Subject: $subject\n\n";
> >
> >          # Email Body
> >          print MAIL $message;
> >
> >          # Send email & confirm
> >          $result = close(MAIL);
> >          if($result) {  print "Se envió mensaje a $to\n";} else {  print
> > "Falló el envío del mensaje a $to!\n";}
> >
> >          $i++;
> >      }  # END IF
> >   }    # END FOREACH
> >
> >  print "Se enviaron $i mensajes de cumpleaños\n";
> >  1;
> > =========================
> >
> > To run from the command line:
> >
> > # perl /PATHTOSCRIPT/koha_birthdays.pl
> >
> > To run on a cron job
> >
> > add
> >
> > /usr/bin/perl  /PATHTOSCRIPT/koha_birthdays.pl to, for
> > example /etc/cron.daily/koha-common or if you are to use crontab you can
> > add:
> >
> > 0 7 * * *  USER /usr/bin/perl  /PATHTOSCRIPT/koha_birthdays.pl
> >
> > This will run the script every day at 7:00 am and will use user USER
> > privileges to run it.
> >
> > Hope this helps.
> >
> > Regards
> >
> > Alvaro
> >
> >
> |----------------------------------------------------------------------------------------|
> >  Stay safe / Cuídate/  Reste sécurisé
> > *7* Switch off as you go / Apaga lo que no usas /  Débranchez au fur et à
> > mesure.
> >  *q *Recycle always / Recicla siempre / Recyclez toujours
> >  P Print only if absolutely necessary / Imprime solo si es necesario /
> > Imprimez seulement si nécessaire
> >
> >
> > Le jeu. 5 nov. 2020 à 18:42, <pandian at imsc.res.in> a écrit :
> >
> >> Dear Alvaro,
> >>
> >> Thanks, yes can you please share the script codes so that we can use it.
> >>
> >> Regards
> >>
> >> Pandian
> >>
> >> Quoting Alvaro Cornejo <cornejo.alvaro at gmail.com>:
> >>
> >> > Hi
> >> >
> >> > We have created a public report in koha that provides us the info we
> need
> >> > to send the emails and created a script that parses the output of that
> >> > report and sends the email. We finally run this script with a cronjob.
> >> >
> >> > I can share the report and script if you think it will help you.
> >> >
> >> > Regards
> >> >
> >> > Alvaro
> >> >
> >>
> |----------------------------------------------------------------------------------------|
> >> >  Stay safe / Cuídate/  Reste sécurisé
> >> > *7* Switch off as you go / Apaga lo que no usas /  Débranchez au fur
> et à
> >> > mesure.
> >> >  *q *Recycle always / Recicla siempre / Recyclez toujours
> >> >  P Print only if absolutely necessary / Imprime solo si es necesario /
> >> > Imprimez seulement si nécessaire
> >> >
> >> >
> >> > Le mer. 4 nov. 2020 à 12:56, Owen Leonard <oleonard at myacpl.org> a
> écrit
> >> :
> >> >
> >> >> > So how can we make this possible to send birthday wishes from Koha?
> >> >>
> >> >> Currently it is not possible. There is an open bug for this, but so
> >> >> far no one has taken it on:
> >> >>
> >> >> https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=22086
> >> >>
> >> >>   Owen
> >> >>
> >> >> --
> >> >> Web Developer
> >> >> Athens County Public Libraries
> >> >> (740) 737-6006
> >> >> https://www.myacpl.org
> >> >> _______________________________________________
> >> >>
> >> >> Koha mailing list  http://koha-community.org
> >> >> Koha at lists.katipo.co.nz
> >> >> Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
> >> >>
> >> > _______________________________________________
> >> >
> >> > Koha mailing list  http://koha-community.org
> >> > Koha at lists.katipo.co.nz
> >> > Unsubscribe: https://lists.katipo.co.nz/mailman/listinfo/koha
> >>
> >>
> >>
>
>
>


More information about the Koha mailing list