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.
=====================================================
#!/usr/bin/perl
# 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
$sql
EOF
];
}
@tables= mysql(q[show tables like '%_set';]);
$ctime=time;
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+)/) {
$set=$1;
$stamp=$2;
next if ($stamp < $ctime);
next if ($stamp-24*60*60 > $ctime);
$lt=localtime($stamp);
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";
$sender->Open({
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.");
$sender->Close()
or print "Failed to send the message: $sender->{'error_msg'}\n";
}
}
}
}