Gossamer Forum
Home : Products : DBMan : Customization :

Email Notification with a BIG Twist

Quote Reply
Email Notification with a BIG Twist
Hello y'all...

I have a current challenge in one of my database programs. Sorry to confuse you again, Carol...I have now implemented a Password Directory program powered by DBMAN at my job. We are using this program to store passwords and userids for our NT Server (For those security freaks out there...don't worry, I have provided a dual login system-one via O'Reilly WebSite1.1 and the other through the DBMAN login screen. No one is allowed to view the database except for certain users with administrative and data entry permissions.) Smile

Anyway, here is my challenge...What I would like to do is create a field known as "Change". This will only be checked in the modification screen when I have successfully changed the user's NT password in the NT User Manager. When this field is checked, then an email message will be sent to the user in the record to notify them that their NT Account has been updated and they can access their account. (This will assist our Help Desk person who currently has to call every user when their password has been updated on the NT Server.) Also, I would only like to send email notifications WHEN their NT accounts have been changed noted by the "Change" field.

I know that I will probably need to modify the validate_record sub-routine. Here is what I have done so far:

In default.cgi, modify_record sub-routine:

1) Added the following code:

Code:
%rec = &get_record($in{$db_key});

AFTER

Code:
my ($status, $line, @lines, @data, $output, $found, $restricted);

2) Added SMTP Mailer statements:

Code:
if (($rec{'Change'} eq 'Yes') && ($rec{'Email'})) {
my $mailer = new Mailer ( { smtp => 'mysmtpserver' } ) or die "Can't init mailer: $Mailer::error";
$mailer->send ( {
to => '$rec{'Email'}',
from => 'webmstr@coco.cc.az.us',
subject => "CCC: NT Account has been Modified",
msg => $modify_body_text
} )
or die "Can't send mail: $Mailer::error";
}

In default.cfg:

1) Added an Email Field
2) Added $modify_body_text

Anyone have any ideas about what I need to add to the validate_record sub-routine that will allow the above stated process to occur.

Currently, without modifying the validate_record sub-routine, the record is modified but the browser hangs and no mail is sent.

TIA.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 03, 1999).]

[This message has been edited by Eliot (edited August 03, 1999).]

[This message has been edited by Eliot (edited August 03, 1999).]

[This message has been edited by Eliot (edited August 03, 1999).]

[This message has been edited by Eliot (edited August 03, 1999).]
Quote Reply
Re: Email Notification with a BIG Twist In reply to
First off, I'm not sure why you have the

%rec = &get_record($in{$db_key});

in sub modify_record. All of the values of the fields will be in the %in hash when the subroutine is called. In your mailer subroutine, just use $in{'Fieldname'}.

Second, there is no need to have a "Change" field in your database. You can add the checkbox to the form without adding the field. It, too, would be in the %in hash. So you would use

Code:
if (($in{'Change'}) && ($in{'Email'})) {

I'm not sure what you need to change in sub validate_record, or if you need to change anything at all.

When you run your script, do you get the modify success page, even though the email isn't sent?


------------------
JPD





Quote Reply
Re: Email Notification with a BIG Twist In reply to
Thanks, Carol. Yes, I need to have the modify_success screen to confirm that the record has been modified. The email message is sent to the email address in the record.
I have not figured out how to use Bcc: in with the SMTP Mailer yet. But I hope to have this problem solved soon, so that a copy of the message will also be sent to me.

The reason I included
%rec = &get_record($in{$db_key}); was because I thought that I needed to pull information from the record by this code. I guess I was wrong.

Quote:
Second, there is no need to have a "Change" field in your database. You can add the
checkbox to the form without adding the field. It, too, would be in the %in hash. So you would use...

Hmm...that makes sense. I will try this tomorrow at the office. I'll let you know how it works out.

Thanks again for your assistance and rapid response.

Smile

Regards,



------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 03, 1999).]
Quote Reply
Re: Email Notification with a BIG Twist In reply to
 
Quote:
Yes, I need to have the modify_success screen to confirm that the record has been modified.

I know that. What I'm asking is if, with your current modification, you are able to get the modify_success screen.

Quote:
The email message is sent to the email address in the record.

But earlier you said

Quote:
Currently, without modifying the validate_record sub-routine, the record is modified but the browser hangs and no mail is sent.

I'm really confused.

I'm just trying right now to figure out the current status of your code.


------------------
JPD





Quote Reply
Re: Email Notification with a BIG Twist In reply to
OH...The current status is that the modification screen does appear, but the browser hangs and no email sent.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Email Notification with a BIG Twist In reply to
Thanks, Carol. The mailer codes are fine. They are working fine in the Add Record and Delete Record sub-routines. The problem is customizing the Modify Record Mailer to send to the email address in the record that was modified.

I am about to try your earlier suggestions. I will let you know how it works.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Email Notification with a BIG Twist In reply to
JPDeni (Carol),

THANKS! It worked like a charm! Smile

I changed the following line from:

Code:
if (($rec{'Change'} eq 'Yes') && ($rec{'Email'})) {

TO

Code:
if (($in{'Change'}) && ($in{'Email'})) {

Thanks again. You're the best!

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 04, 1999).]

[This message has been edited by Eliot (edited August 04, 1999).]

[This message has been edited by Eliot (edited August 04, 1999).]
Quote Reply
Re: Email Notification with a BIG Twist In reply to
Okay...another challenge...I attempted to set-up two different modification forms: 1) Data Manager can modify records without the "Change" checkbox included, and 2) Administrator can modify records with the "Change" checkbox included. The reason I want to do this is that I do not want to risk the Data Manager accidentially or intentially clicking on Change when the NT password may not have been changed yet.

I have currently inserted the following codes:

Code:
|;
if ($per_admin){
&html_record_modify_admin_form();
}
else {
&html_record_modify_form();
}
print qq|

in both of the following sub-routines:

1) sub html_modify_search
2) sub html_modify_form_record

The modification form does appear correctly for both the administrator and data manager. However, when I try to pull-up a record to modify (both by "list all" and search form), no records are pulled up.

Any ideas?

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 04, 1999).]

[This message has been edited by Eliot (edited August 04, 1999).]
Quote Reply
Re: Email Notification with a BIG Twist In reply to
Okay. Now I got it. Smile

Two things to check. Make sure that $in{'Email'} (or $rec{'Email'} if you want to go that route) actually exists and that $in{'Change'} exists. You might want to have those printed out in html_modify_success just to be sure.

The other thing is to make sure that the mailer code works.


------------------
JPD





Quote Reply
Re: Email Notification with a BIG Twist In reply to
Hello Eliot

can you please post the changes I need to make to the dbman to send a email if the dbase is modiffied

Thanks

Evan
Quote Reply
Re: Email Notification with a BIG Twist In reply to
Here are the codes: (For SMTP Mailer and Sendmail)

==========================================
SMTP Mailer
==========================================
You must first download the Mailer.pm, which is available in the LINKS package. Then in your default.cfg file, add this line of code in your authorization section:

Code:
# Full path and file name of the Mailer Program.
require $mailer_path . "/Mailer.pm";

Then in the default.cgi file, add this line of code:

Code:
$mailer_path ="/path/cgi-bin/sendmail";

For a simple message that will send out an email message notifying the webmaster or data manager that a record has been added, use these instructions:

In add_record sub-routine in default.cgi:

1) Add the following codes AFTER &html_add_success; in the add_record:

Code:
# Send email when new record is added

my $mailer = new Mailer ( { smtp => 'SMTPSERVER' } ) or die "Can't init mailer: $Mailer::error";

$mailer->send ( {
to => 'Recipient Email Address',
from => 'Your Email Address',
subject => "Record Added to Database",
msg => "Message"
} )
or die "Can't send mail: $Mailer::error";

2) Replace the following statements:

* SMTPSERVER = Your SMTP Server
* Recipient Email Address = Your email address
* Your Email Address = Your email address or the server admin address
* Message = Message you want to send.

If you want to send a detailed message to the record owner, use these instructions:

In add_record sub-routine in default.cgi:

1) Add the following codes AFTER ($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);:

Code:
%rec = &get_record($in{$db_key});

2) Add the following codes AFTER &html_add_success; in the add_record:

Code:
# Send email when new record is added

my $mailer = new Mailer ( { smtp => 'SMTPSERVER' } ) or die "Can't init mailer: $Mailer::error";

$mailer->send ( {
to => '$in{'Email'},',
from => 'Your Email Address',
subject => "Record Added to Database",
msg => "Message"
} )
or die "Can't send mail: $Mailer::error";

3) Replace the following statements:

* SMTPSERVER = Your SMTP Server
* Your Email Address = Your email address or the server admin address
* Message = Message you want to send.

Note: In the Message variable ($msg), you can add a complete record report by including fields in the following fashion:

$in{'FieldName'}

Change FieldName with the appropriate field name(s) that are located in your default.cfg file.

==========================================
Sendmail Program
==========================================
For a simple message that will send out an email message notifying the webmaster or data manager that a record has been added, use these instructions:

1) In default.cfg, add these lines of code after the reference for html.pl

Code:
# Full path to sendmail on your system
$mailprog = "|/usr/lib/sendmail -t -oeq";

# Your email address
$admin_email= 'YOUR EMAIL ADDRESS';

Replace YOUR EMAIL ADDRESS with your email address.

In add_record sub-routine in default.cgi:

2) Add the following codes AFTER &html_add_success;:

Code:
open (MAIL, "$mailprog") | | &cgierr("unable to open mail program");
print MAIL "To : youraccount\@server.com\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Record Added to $html_title\n\n";
print MAIL "You have added a record to the $html_title\n\n";
close (MAIL);

Replace the bolded statement with your email addresses. Make sure that you put a \ before @.

If you want to send a detailed message to the record owner, use these instructions:

In add_record sub-routine in default.cgi:

1) Add the following codes AFTER ($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);:

Code:
%rec = &get_record($in{$db_key});

2) Add the following codes AFTER &html_add_success; in the add_record:

Code:
open (PASSWD, "<$auth_pw_file") or &cgierr("unable to open password file. Reason: $!\n");
if ($db_use_flock) {
flock(PASSWD, 2) or &cgierr("unable to get exclusive lock on $auth_pw_file.\nReason: $!");
}
@passwds = <PASSWD>;
close PASSWD;
foreach $pass (@passwds) {
if ($pass =~ /^$db_userid:/) {
@data = split ":",$pass;
$email = $data[7];
last;
}
}
open (MAIL, "$mailprog") | | &cgierr("unable to open mail program");
print MAIL "To: $email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Record Added to $html_title\n\n";
print MAIL "You have added a record to the $html_title\n\n";
print MAIL "Please save this message for future reference.\n\n";
print MAIL "Your record ID is: $rec{'ID'}\n\n";

Note: In the Message variable ($msg), you can add a complete record report by including fields in the following fashion:

$rec{'FieldName'}

Change FieldName with the appropriate field name(s) that are located in your default.cfg file.

This particular modification requires the NEWEST password lookup mod. But you could just delete the codes before open (MAIL...and add the EMAIL field in the To line. (If you have an email field).

These modifications can be added to the modify_record and delete_record. Make sure that you insert the "mailing" codes ($mailer or open (MAIL...) after the following codes:

In modify_record:

Code:
&html_modify_success;

In delete_records:

Code:
&html_delete_success;

I really hope this helps. If you have any questions, let me know.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited August 04, 1999).]
Quote Reply
Re: Email Notification with a BIG Twist In reply to
Dah...I got the multiple modification form to work. I just had to add the following codes:

Code:
if ($per_admin) {
&html_record_modify_admin_form (%rec);
}
else {
html_record_modify_form (%rec);
print "</TABLE></div></center>";
}

to the modify_form_record ONLY.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Email Notification In reply to
OK, managed to get Eliot's e-mail notification to work nicely when non-admin users add to the database. However, I would like to also use CC and BCC fields. It makes no difference whether I add:

print MAIL "CC: $admin_email\n"; or
print MAIL "BCC: $admin_email\n";

only 1 mail gets sent to the recipient. Am I missing something else??

I am using the sendmail option on RH6.1/apache 1.3.9 is that makes a difference.

Best regards, Brian

Quote Reply
Re: Email Notification In reply to
This has been taken from the FAQ noted below under "Email"

BCC, CC, and Return Path

There are several variables you can define when sending email. View the following
examples to see if there is something you want to try in your script.

Added two things in the send mail.
1. A return path
2. BCC (blind carbon copy)

The admin gets a copy of the email, and bounced emails return to the system. You
can also include the date.

sub sendemail {
#----------------------------
$returnpath="xxx\@yyy.com";
$FROM="sss\@yyy.com";
$TO=$_[0];
@TO=split('\0',$TO);
$BCC="xxx\@yyyc.com";
$SUBJECT=$_[1];
$REPLYTO="sss\@yyy.com";
$REMOTE = $_[3];
$THEMESSAGE = $_[4];
$nowtime = localtime(time);
open(S, "|$REMOTE -t");
print S "Return-Path: $returnpath\n";
print S "To: $TO[0]\n";
print S "BCC: $BCC\n";
print S "From: $FROM\n";
print S "Subject: $SUBJECT\n";
print S "-" x 75 . "\n\n";
print S "Date: $nowtime\n";
print S "Reply-To: $REPLYTO\n\n";
# Print the body
print S "$THEMESSAGE\n";
print S "\n";
print S ".\n";
close (S);
}

OR this version:

sub sendemail {
#----------------------------
$returnpath="xxx\@yyy.com";
$FROM="sss\@yyy.com";
$TO=$_[0];
@TO=split('\0',$TO);
$BCC="xxx\@yyyc.com";
$SUBJECT=$_[1];
$REPLYTO="sss\@yyy.com";
$REMOTE = $_[3];
$THEMESSAGE = $_[4];
$nowtime = localtime(time);

open (MAIL, "|/usr/lib/sendmail -t");
print MAIL "Return-Path: $returnpath\n";
print MAIL "To: $TO[0]\n";
print MAIL "BCC: $BCC\n";
print MAIL "From: $FROM\n";
print MAIL "Subject: $SUBJECT\n";
print MAIL "-" x 75 . "\n\n";
print MAIL "Date: $nowtime\n";
print MAIL "Reply-To: $REPLYTO\n\n";
# Print the body
print MAIL "$THEMESSAGE\n";
print MAIL "\n\n";
close (MAIL);
}

This has worked for others .. let me know if it helps.

Unoffical DBMan FAQ
http://webmagic.hypermart.net/dbman/
Quote Reply
Re: Email Notification In reply to
As I say, neither $CC or $BCC fields work with sendmail.

In the end I just wrote out the sendmail text twice to write the message to 2 different users.

Best regards, Brian

Quote Reply
Re: [Eliot] Email Notification with a BIG Twist In reply to
I have used the Sendmail email mod and it works...now I want to use the SMTP email mod. I have been searching for how to do this and this seems to be the right thread to look at....I am however a little confused:

What is this file mailer.pm?

what is the links package?



further more, has anyone gotten this to work? are you able to provide the right files? maybe even write this up as a mod???? (everywhere I look there seems to be only fragments!)

I'll be waiting.....thank you for your time.

Quote:


You must first download the Mailer.pm, which is available in the LINKS package. Then in your default.cfg file, add this line of code in your authorization section:
Quote Reply
Re: [mabel] Email Notification with a BIG Twist In reply to
mailer.pm is as module include with the GT Links script.

You may want to check out this thread:

Thread: http://gossamer-threads.com/p/53058
Topic: Mailing
Jaime Ortega - January 14, 1999

and also search for SMTP in all the forums. Especially in the programmer's forum as I believe there are posts regarding this to be found there.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/