WeBWorK Main Forum

email reminder of due dates

Re: email reminder of due dates

by Nandor Sieben -
Number of replies: 0
I wrote a rudimentary perl script that does this. It could be greatly
improved with more sophisticated timing of the message. I run this 
as a cron job once a day. It gets the info from the database server. 

# WarnDueDate 
# Sends an email to students with a set due in the next 24 hours.  
# Author: Nandor Sieben  

use Mail::Sender;

sub mysql {
my ($sql) = @_;
# print "$sql\n"; 
qx[mysql -s -u webworkWrite --host=myserver.edu -pmypassword webwork << EOF  

@tables= mysql(q[show tables like '%_set';]);


foreach $table (@tables) {
  chop $table;
  @rows=mysql(qq[select set_id, due_date from $table]);
  foreach $row (@rows) {
     $table =~s /.set\Z//;
     if ( $row =~ /(\S+)\s+(\S+)/) {
       next if ($stamp < $ctime);
       next if ($stamp-24*60*60 > $ctime);
       print "$table \t $lt \t $set \n";
       @emails=mysql(qq[select email\_address from $table\_user]);
       foreach $email (@emails) {
         print $email;
         $sender = new Mail::Sender {
                 smtp => 'mailgate.myschool.edu',
                 from => 'webwork@myschool.edu',
                 on_errors => undef,
         or print "Can't create the Mail::Sender object: $Mail::Sender::Error\n";
                 to => "$email",
                 cc => '',
                 subject => "$set is due soon"
         or print "Can't open the message: $sender->{'error_msg'}\n";
         $sender->SendLineEnc("This is an automatic message generated by the WeBWorK system.\n");
         $sender->SendLineEnc("WeBWorK set $set in class $table");
         $sender->SendLineEnc("is due on $lt.");
         or print "Failed to send the message: $sender->{'error_msg'}\n";