Gossamer Forum
Home : General : Perl Programming :

Sending Email to Users in Database File

Quote Reply
Sending Email to Users in Database File
Hello.

I originally posted this Topic over in DBMAN Discussion since my main goal is to send mass email messages to users within a DBMAN database file. Carol did a wonderful job in getting me started...but I think the problems are related to general Perl problems, than with DBMAN, so I am moving the discussion here.

To see the history of this problem, go to http://www.gossamer-threads.com/...m12/HTML/000628.html

Here is what I have...A separate stand alone email script that uses information within a DBMAN file to send out email to specific users with email addresses in the database file.

Here is the script I have written (with the help of Carol and others):

Code:
@referers = ('http://www.coco.cc.az.us','http://wookie.coco.cc.az.us','http://spock.coco.cc.az.us');

&Check_URL;

open (DB, "<$db_path/$db_file_name") or ("unable to open password file. Reason: $!\n");
if ($db_use_flock) {
flock(DB, 2);
}
@lines = <DB>;
close DB;

foreach $line (@lines) {
@data = split "|",$line;
$email = $data[21];
$user = $data[3];
if (($user) && ($email)) {
my $mailer = new Mailer ( { smtp => 'yoda.coco.cc.az.us' } )
or die "Can't init mailer: $Mailer::error";
$mailer->send ( {
to => '$email',
from => '$admin_mail',
subject => 'NT Password has Expired',
msg => $notify_body_text
} )
or die "Can't send mail: $Mailer::error";
}
}
&logging;

(This is the main part of the script...the configuration variables are set-up properly and the sub-routines work fine...I thought that to save time in downloading this page, it would be best to only provide the main part of the script. Also, the path to perl is correct.)

BTW: The data fields are also correct. Field [3] is "UserName", which denotes a certain type of account that the user has in our network. Field [21] is "Email", which denotes email address of the user.

Please post your suggestions about what I need to add to this script or how I can edit this to make it work.

Thanks.

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: Sending Email to Users in Database File In reply to
I am getting there...I noticed another Thread that addressed the problems I am having:

www.gossamer-threads.com/scripts/forum/resources/Forum8/HTML/000113.html

I made the edits located in this Thread, including changing the split command from:

Code:
@data = split "|",$line;

TO

Code:
@data = split /\|/,$line;

I also added the following codes:

Code:
if (!$data[21]) {
print "Content-type: text/html\n\n";
print "No Email Address or User Name defined in @data!";
exit;
}

BEFORE

Code:
if (($user) && ($email)) {

The problem is that I was only able to execute this script ONCE. It worked ONLY one time. I need to have this script executed by AT Scheduler (Cron for NT) every 40 days.

I don't see any syntax problems. Does anyone know how I can modify the following codes to send the mail message multiple times??

Code:
#############################################################
# Open the Database
#############################################################

open (DB, "<$db_path/$db_file_name") or ("unable to open password file. Reason: $!\n");
if ($db_use_flock) {
flock(DB, 2);
}
@lines = <DB>;
close DB;

#############################################################
# Start Loop
#############################################################

foreach $line (@lines) {
@data = split /\|/,$line;
$email = $data[21];
$user = $data[3];
if (!$data[21]) {
print "Content-type: text/html\n\n";
print "No Email Address or User Name defined in @data!";
exit;
}
if (($user) && ($email)) {

#############################################################
# Mail Routine
#############################################################

my $mailer = new Mailer ( { smtp => 'yoda.coco.cc.az.us' } )
or die "Can't init mailer: $Mailer::error";
$mailer->send ( {
to => '$email',
from => '$admin_mail',
subject => "NT Password has Expired",
msg => $notify_body_text
} )
or die "Can't send mail: $Mailer::error";
}
}

(The above codes are revised from my first Post.)

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 13, 1999).]
Quote Reply
Re: Sending Email to Users in Database File In reply to
Still having problems attempting to execute this script multiple times. It only executes once via my web browser. I also attempted using the AT Scheduler and it did not work.

Based on advice given by kipt, I installed a counter routine that would execute the script after a certain period of time. This failed miserably and ate tons of CPU, which forced me to re-boot our server.

Really would appreciate some ideas or suggestions for this type of script.

Thanks. Wink

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: Sending Email to Users in Database File In reply to
Anyone have suggestions of how I can get this script to work?

Thanks in advance.

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