[LON-CAPA-cvs] cvs: loncom /interface lonmsg.pm
www
lon-capa-cvs@mail.lon-capa.org
Wed, 02 Apr 2003 00:50:46 -0000
www Tue Apr 1 19:50:46 2003 EDT
Modified files:
/loncom/interface lonmsg.pm
Log:
Sends notification emails.
Index: loncom/interface/lonmsg.pm
diff -u loncom/interface/lonmsg.pm:1.52 loncom/interface/lonmsg.pm:1.53
--- loncom/interface/lonmsg.pm:1.52 Mon Mar 31 11:34:08 2003
+++ loncom/interface/lonmsg.pm Tue Apr 1 19:50:46 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines for messaging
#
-# $Id: lonmsg.pm,v 1.52 2003/03/31 16:34:08 www Exp $
+# $Id: lonmsg.pm,v 1.53 2003/04/02 00:50:46 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -52,6 +52,7 @@
use Apache::loncommon();
use Apache::lontexconvert();
use HTML::Entities();
+use Mail::Send;
# ===================================================================== Package
@@ -142,6 +143,42 @@
return ($sendtime,$shortsubj,$fromname,$fromdomain,$status{$msgid});
}
+
+sub sendemail {
+ my ($to,$subject,$body)=@_;
+ $body=
+ "*** This is an automatic message generated by the LON-CAPA system.\n".
+ "*** Please do not reply to this address.\n\n".$body;
+ my $msg = new Mail::Send;
+ $msg->to($to);
+ $msg->subject('[LON-CAPA] '.$subject);
+ my $fh = $msg->open('smtp',Server => 'localhost');
+ print $fh $body;
+ $fh->close;
+}
+
+# ==================================================== Send notification emails
+
+sub sendnotification {
+ my ($to,$touname,$toudom,$subj,$crit)=@_;
+ my $sender=$ENV{'environment.firstname'}.' '.$ENV{'environment.lastname'};
+ my $critical=($crit?' critical':'');
+ my $url='http://'.
+ $Apache::lonnet::hostname{&Apache::lonnet::homeserver($touname,$toudom)}.
+ '/adm/login&username='.$touname.'&domain='.$toudom;
+ my $body=(<<ENDMSG);
+You received a$critical message from $sender in LON-CAPA. The subject is
+
+ $subj
+
+Use
+
+ $url
+
+to access this message.
+ENDMSG
+ &sendemail($to,'New'.$critical.' message from '.$sender,$body);
+}
# ============================================================= Check for email
sub newmail {
@@ -199,6 +236,13 @@
} else {
$status='no_host';
}
+# Notifications
+ my %userenv = &Apache::lonnet::get('environment',['critnotification'],
+ $domain,$user);
+ if ($userenv{'critnotification'}) {
+ &sendnotification($userenv{'critnotification'},$user,$domain,$subject,1);
+ }
+# Log this
&Apache::lonnet::logthis(
'Sending critical email '.$msgid.
', log status: '.
@@ -276,6 +320,12 @@
('email_status',{'recnewemail'=>time},$domain,$user);
} else {
$status='no_host';
+ }
+# Notifications
+ my %userenv = &Apache::lonnet::get('environment',['notification'],
+ $domain,$user);
+ if ($userenv{'notification'}) {
+ &sendnotification($userenv{'notification'},$user,$domain,$subject,0);
}
&Apache::lonnet::log($ENV{'user.domain'},$ENV{'user.name'},
$ENV{'user.home'},