I have seen many discussions about sending email from the database. In fact, I came to this forum earlier this week for some ideas. I would like to share what I have been able to make work even though I am just a beginner with PERL. Here is what I have done to send an email of an added record to a recipient identified by a field using blat on NT:
I added parts to db.cgi under sub add_record (compare the two to see the differences):
if ($status eq "ok") {
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
open (MAIL, ">$db_blat_file") or &cgierr("error in add_record. unable to open database: $db_blat_file.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
flock(MAIL, 2) or &cgierr("unable to get exclusive lock on $db_blat_file.\nReason: $!");
}
print DB &join_encode(%in);
# Put the information from the database form into a temp file - blat
# sends the contents of a file via email. If you don't store it as a file first, it
# won't send the mail - you will get an error telling you the file
# does not exist.
print MAIL "Subject: NJVCCC Registration\n\n";
print MAIL "The following $in{'County'}";
print MAIL " county student has registered for your provided course:\n\n";
print MAIL "$in{'Subject'}";
print MAIL " : $in{'Course'}";
print MAIL " - $in{'Section'}";
print MAIL " for the $in{'Semester'}";
print MAIL " Semester\n\n";
print MAIL "Social Security Number: $in{'Social'}\n";
print MAIL "$in{'First_Name'}";
print MAIL " $in{'Last_Name'}\n";
print MAIL "$in{'Address'}";
print MAIL " $in{'Apartment'}\n";
print MAIL "$in{'City'}";
print MAIL ", $in{'State'}";
print MAIL " $in{'Zip_Code'}\n";
print MAIL "$in{'Phone'}\n";
print MAIL "$in{'email'}\n\n";
print MAIL "Have a great day!\n\n";
print MAIL "Amy Shelton\n";
print MAIL "Atlantic Cape Community College\n";
print MAIL "\n\n";
close DB; # automatically removes file lock
close MAIL; # automatically removes file lock
if ($db_key_track) {
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_add_success;
#Send the mail here
$in{'recipient'} =~ s/\//\\/g;
$db_blat_file =~ s/\//\\/g;
system "blat.exe $db_blat_file -t $in{'recipient'} -q";
}
else {
&html_add_failure($status);
}
}
And to default.cfg you must add the following:
# Full Path and File name of the blat file to be emailed.
$db_blat_file = $db_script_path . "/blat.txt";
to the file and URL's section.
Hope this helps someone.....
Amy Shelton
Atlantic Cape Community College
[This message has been edited by shelton (edited March 27, 2000).]
I added parts to db.cgi under sub add_record (compare the two to see the differences):
if ($status eq "ok") {
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
open (MAIL, ">$db_blat_file") or &cgierr("error in add_record. unable to open database: $db_blat_file.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
flock(MAIL, 2) or &cgierr("unable to get exclusive lock on $db_blat_file.\nReason: $!");
}
print DB &join_encode(%in);
# Put the information from the database form into a temp file - blat
# sends the contents of a file via email. If you don't store it as a file first, it
# won't send the mail - you will get an error telling you the file
# does not exist.
print MAIL "Subject: NJVCCC Registration\n\n";
print MAIL "The following $in{'County'}";
print MAIL " county student has registered for your provided course:\n\n";
print MAIL "$in{'Subject'}";
print MAIL " : $in{'Course'}";
print MAIL " - $in{'Section'}";
print MAIL " for the $in{'Semester'}";
print MAIL " Semester\n\n";
print MAIL "Social Security Number: $in{'Social'}\n";
print MAIL "$in{'First_Name'}";
print MAIL " $in{'Last_Name'}\n";
print MAIL "$in{'Address'}";
print MAIL " $in{'Apartment'}\n";
print MAIL "$in{'City'}";
print MAIL ", $in{'State'}";
print MAIL " $in{'Zip_Code'}\n";
print MAIL "$in{'Phone'}\n";
print MAIL "$in{'email'}\n\n";
print MAIL "Have a great day!\n\n";
print MAIL "Amy Shelton\n";
print MAIL "Atlantic Cape Community College\n";
print MAIL "\n\n";
close DB; # automatically removes file lock
close MAIL; # automatically removes file lock
if ($db_key_track) {
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_add_success;
#Send the mail here
$in{'recipient'} =~ s/\//\\/g;
$db_blat_file =~ s/\//\\/g;
system "blat.exe $db_blat_file -t $in{'recipient'} -q";
}
else {
&html_add_failure($status);
}
}
And to default.cfg you must add the following:
# Full Path and File name of the blat file to be emailed.
$db_blat_file = $db_script_path . "/blat.txt";
to the file and URL's section.
Hope this helps someone.....
Amy Shelton
Atlantic Cape Community College
[This message has been edited by shelton (edited March 27, 2000).]