Gossamer Forum
Home : Products : DBMan : Installation :

Old email notify question with a twist.

Quote Reply
Old email notify question with a twist.
Ok I've searched the board and have seen the question "can I be email notified when a new user is added" and also "can I be email notified when a record is changed" I've seen other similar questions that say search the board.

Mine is a little different. I need an email to be sent to me only when a new record has been completed and added successfully. Not when someone registers or modifies a record.

I looked at examples and tried to modify them to no avail that were found in 000459.htm and 000454.htm. I have tried inserting language in html.pl and db.cgi based on these. I know I can figure it out if JPDENI tells me exactly how to do it. (I guess that means I can't figure it out).

Specifically, I would like the email to come to me with the Date the record was added and the Userid of the person that added it. I don't have the key set on Userid but on ID, does this matter...Ignore that if irrelevant. Thats the least of my problems.

If possible I would like to know what file I insert the language in, exactly where to put it. such as an example of what it used to look like and what it should look like after modified.

JPDENI if your out there I hope you get paid for this.... Can you or anyone help? This is my last mod to get this thing online.....

Craig (wave3)
Quote Reply
Re: Old email notify question with a twist. In reply to
What do you mean by "no success"? Are you not getting the email? Do you get any error message?

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





Quote Reply
Re: Old email notify question with a twist. In reply to
Yes, unfortunately thats waht I mean. I get no error message and I get no email..... I wondering if its a problem with my sever. Do you have any ideas? Thanks again for your input....
Quote Reply
Re: Old email notify question with a twist. In reply to
No, I'm not getting paid for this. Smile I do it because most of the time it's fun to do and it does give me a little advertising for my own customization business.

First, find out the path to "sendmail" on your system. You may have to ask your sysadmin. Once you know what it is, add the following lines to your default.cfg file:

Code:
# Your email address. Be sure to keep the \ before the @.
$admin_email = "you\@yourserver.com";
# Path to sendmail
$mailprog = "|/usr/lib/sendmail -t -oeq";

You'll want to leave in the | and the -t -oeq parts. Just change the path if your path is different from what I have above.

Save the default.cfg file.

Open the html.pl file.

Look for sub html_add_success.

Before the line

Code:
&html_print_headers;

add

Code:
%rec = &get_record($in{$db_key});
$date = &get_date();
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");

print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: New Record Added\n\n";

print MAIL "Date added: $date\n";
print MAIL "Userid: $rec{'Userid'}\n";
close MAIL;

If your fieldname for the userid is not called Userid, be sure to change $rec{'Userid'} to match the actual name of your field.

That should do it.

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





Quote Reply
Re: Old email notify question with a twist. In reply to
Ok I set it up as you stated. Please look over this as I still have had no success. I checked the path of my sendmail and its ok. Here is what my default.cfg looks like. I pasted a few of the surrounding lines so you can see if its in the right place

code:
# Full path and file name of the log file.
$auth_log_file = $db_script_path . "/default.log";
# Full path and file name of the html routines.
require $db_script_path . "/html.pl";
# Your email address. Be sure to keep the \ before the @.
$admin_email = "wave3\@mcs.net";
# Path to sendmail
$mailprog = "|/usr/bin/sendmail -t -oeq";


# Database Definition
# --------------------------------------------------------

My html.pl Looks Like this:

sub html_add_success {
# --------------------------------------------------------
# The page that is returned upon a successful addition to
# the database. You should use &get_record and &html_record
# to verify that the record was inserted properly and to make
# updating easier.

$page_title = "Record Added";
%rec = &get_record($in{$db_key});
$date = &get_date();
open (MAIL, "$mailprog") or &cgierr("Can't start mail program");

print MAIL "To: $admin_email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: New Record Added\n\n";
print MAIL "Date added: $date\n";
print MAIL "Userid: $rec{'Userid'}\n";
close MAIL;

&html_page_top;

# < -- Start page text -- >
print qq|
<P><$font>The following record was successfully added to the database:</FONT>
|;
# < -- End page text -->
I contacted the host server and they tell me send mail is working.
Can you see anything wrong? I bolded the text you wanted me to insert.....
Thanks Craig
Quote Reply
Re: Old email notify question with a twist. In reply to
OK. Ihope this help You it works for me so Here is a example of sub add_record in db.cgi

sub add_record {
# --------------------------------------------------------
# Adds a record to the database. First, validate_record is called
# to make sure the record is ok to add. If it is, then the record is
# encoded and added to the database and the user is sent to
# html_add_success, otherwise the user is sent to html_add_failure with
# an error message explaining why. The counter file is also updated to the
# next number.

my ($output, $status, $counter);
# Set the userid to the logged in user.
($auth_user_field >= 0) and ($in{$db_cols[$auth_user_field]} = $db_userid);

# First we validate the record to make sure the addition is ok.
$status = &validate_record;

# We keep checking for the next available key, or until we've tried 50 times
# after which we give up.
while ($status eq "duplicate key error" and $db_key_track) {
return "duplicate key error" if ($counter++ > 50);
$in{$db_key}++;
$status = &validate_record;
}

if ($status eq "ok") {
open (DB, ">>$db_file_name") or &cgierr("error in add_record. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_name.\nReason: $!");
}
print DB &join_encode(%in);
close DB; # 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;


open (MAIL, "|/usr/lib/sendmail -t") or &cgierr("Can't open sendmail: $!");
print MAIL "To: newrepo\@repoland.com\n";
print MAIL "From: DBMan\n";
print MAIL "Subject: New data added to repoland database !\n\n";
print MAIL "Data was add to Repoland on ", scalar localtime(), ".\n";
print MAIL "Company: $in{'Company'},\n";
print MAIL "State: $in{'State'}\n";
print MAIL "Phone: $in{'Phone'}\n";
print MAIL "Email: $in{'Email'}\n";
Days. \n";
close MAIL;


}

else {
&html_add_failure($status);
}
}

sub delete_records {

I hope this will work for you
But first check the path for Mail program.
Quote Reply
Re: Old email notify question with a twist. In reply to
wave, try take out the -oeq from the $mailprog variable. The reason I put that in there is that it's supposed to catch errors. But right now we kinda need to see errors, so take it out for now. You might want to put it back in later.


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





Quote Reply
Re: Old email notify question with a twist. In reply to
JPDENI
Ok I took off the -oeq and get no error messages at all and no mail. I will try Greegie's mod I suppose unless you have any other suggestions....
wave3
Quote Reply
Re: Old email notify question with a twist. In reply to
JPDeni..... It worked.. I stuck with your example and got into a long discussion with my server.... I asked them to check their mail logs for mail that tried to get sent... They reluctantly did and showed that some mail was shot down.... They just put in some new language to prevent spamming and if you don't use your username before the @ symbol it won't go through.... This is ridicluous but I am happy it worked. Thanks to you also Greggie! What a great board!!!!