Gossamer Forum
Home : Products : DBMan : Customization :

Mass Mailer Modification

Quote Reply
Mass Mailer Modification
I did not see any thread on this particular issue pertaining to JP Deni's Mass Mailer (Last modified: 13 Jul 2001). I am using the non-relational db man and the short/long modification with secure password lookup.
The Mass Mailer is working fine for me and pulls the emails addresses to send its message to from the 'default.pass' file. I would like to pull and use the email addresses that are found in the 'default.db' instead. Can that be accomplished? If so would anyone be willing to explain how?

Reagrds,
Chef Mars
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
Sorry.
The mod I am using is not the Mass Mailer but is the Admin bulk email to all that uses the '<A HREF="$db_script_link_url&send_email_form=1">Send mass mailing</A>' footer link.

Chef Mars
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
Doesn't the file at http://www.jpdeni.com/.../Mods/massmailer.txt do that?

It's been quite a while since I looked at it, but it appears to pull the email addresses from the .db file.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Mass Mailer Modification In reply to
I have not been able to install that file in a way that I can use it. The Mass Mail form ends up sitting on top of my input form with error messages saying "There was a problem: no search terms specified
Fill in the subject of your message, the message you wish to send and the criteria for the users to whom you wish to send the email."


I tried to marry the two cgi sub routines but failed.

Chef Mars
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
What did you use?


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Mass Mailer Modification In reply to
sub send_email {
#-----------------------------------
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (DB, "<$db_file_name") or &cgierr("error in send_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$in{'mh'} = $#lines;
my ($status, @hits) = &query("view");
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_mass_mail_form($message);
return;
}
my ($numhits) = ($#hits+1) / ($#db_cols+1);
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{$db_email_field} =~ /.+\@.+\..+/) {
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL $in{'emailmessage'};
close (MAIL);
++$mail_count;
}
}
&html_send_mail_success($mail_count);
}

I linked to the send_email_form entered a subject and message but when I submitted the form was returned the Mass Mailer Form that was atop my data inout form.
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
What modification are you using now? Where did you get a mod that uses the default.pass file for the email address? I don't have that mod on my site. If I gave it to you (or someone else) in this forum, I don't remember it, so I need to know what you have in your files in order to be able to help you change them.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
Check the name of your subroutine in the html.pl file. It should be

sub html_mass_mail_success

If it is, you need to change

&html_send_mail_success($mail_count);

to

&html_mass_mail_success($mail_count);

I may have had an error there earlier, but then fixed it.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Mass Mailer Modification In reply to
Thank you for you interest and help.
Here is the code for the 2 MODS.
I got the one for send_email_form from a thread titled "Admin bulk email to all" at http://www.gossamer-threads.com/perl/gforum/gforum.cgi?do=post_reply_write;parent_post_id=283611
It works OK but pulls the target email addresses from the password file.
====================================================

Admin bulk email to all
---------------------

##---------------------------------
# file: db.cgi
##---------------------------------

elsif ($in{'send_email_form'}) { if ($per_admin) { &html_send_email_form; } else { &html_unauth; } }
elsif ($in{'send_email'}) { if ($per_admin) { &send_email; } else { &html_unauth; } }


########################################################################
# Somewhere in db.cgi, add the following new subroutine:code:
# For SEND FORM MOD
########################################################################

sub send_email {
##-----------------------------------
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
open (DB, "<$auth_pw_file") or &cgierr("error in send email. unable to open password file: $$auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { next LINE; }
chomp ($line);
@data = split (/:/, $line);
push(@email_list,$data[7]);
}
foreach $email (@email_list) {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $email\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL $in{'emailmessage'};
close (MAIL);
}
&html_send_email_success;
}



##########################################################################>>>

###########################################################################
##### New sub routine added 7.20.03
##### In html.pl add the following two subroutines:code:
##### Added for bulk mailing
###########################################################################

sub html_send_email_form {
#--------------------------------
my ($message) = $_[0];
&html_print_headers;
# <-- top of page formatting -->
print qq|
<HTML><BODY>
<center><table border=1 cellpadding=5 cellspacing=3 width=500>
<tr><td><FONT size=1><b>$html_title: Send an email</b></td></tr>
<tr><td><p><center><$font_title><b>Send an email</b></font></center><br>|;
# <-- introductory text -->
if ($message) { print qq|There was a problem: $message|; }
print qq|
<$font>Fill in <!-- your email address,--> the subject of your email and the message you wish to send.</font>
|;
# <-- email form -->
print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">

<center>
<table BORDER=2 width=450>
<tr><td><$font>Subject:...</font><input type=text name="subject" value="$in{'subject'}" size="40"></td></tr>
<tr><td>---</td></tr>
<tr><td valign=middle><$font>Your message:...</font><textarea name="emailmessage" COLS=40 ROWS=6>$in{'emailmessage'} </textarea></td></tr>
<TR align=center><TD><INPUT TYPE="SUBMIT" NAME="send_email" VALUE="Send Email"> &nbsp; <INPUT TYPE="RESET" VALUE="Reset Form">
</TD></TR>
</table></form></center>
|;
# <-- end of page formatting -->
&html_footer;
print qq|</td></tr></table> </BODY></HTML> |;
}

sub html_send_email_success {
#----------------------------------
&html_print_headers;
# <-- top of page formatting -->
print qq|
<!-- add body tags -->
<center><table border=1 cellpadding=5 cellspacing=3 width=500>
<tr><td><FONT size=1><b>$html_title: Send an email</b></td></tr>
<tr><td><p><center><$font_title><b>Email sent</b></font></center><br>
|;
# <-- text -->
print qq|<$font>Your email message was sent.</font>|;
# <-- end of page formatting -->
&html_footer;
print qq|</td></tr></table> <!-- add body tags --> |;
}

====================================================
The code for the MASS MAILER follows. I got that from your web site. This is the one that appears to pull the target email addresses from the file I want but is presented to me in an unusable form, which produces the error messages I posted earlier.


M A S S M A I L E R
---------------------

##---------------------------------
# file: db.cgi
##---------------------------------

elsif ($in{'mass_mail_form'}) { if ($per_admin) { &html_mass_mail_form; } else { &html_unauth; } }
elsif ($in{'mass_mail'}) { if ($per_admin) { &mass_mail; } else { &html_unauth; } }


##############################################################################
#file: db.cgi
# new subroutine
# sub mass_mail ##############################################################################

sub mass_mail {
# --------------------------------------------------------
# Apparently it runs now properly by changing the line:
# $in{'mh'} = $#lines ;
# with
# $in{'mh'} = $#lines + 1;



my ($i,$message,@lines,$line,$count,%rec,$mail_count);

unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file<BR>"; }
unless ($admin_email =~ /.+\@.+\..+/) { $message = "Admin email address is not in the correct format.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_email_field eq $db_cols[$i]) {
$found = 1;
last;
}
}
if (!$found) {
$message .= "email field not found<BR>";
}
open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$in{'mh'} = $#lines + 1;
my ($status, @hits) = &query("view");
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_mass_mail_form($message);
return;
}
my ($numhits) = ($#hits+1) / ($#db_cols+1);
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{$db_email_field} =~ /.+\@.+\..+/) {
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL $in{'emailmessage'};
close (MAIL);
++$mail_count;
}
}
&html_mass_mail_success($mail_count);
}

##########################################################################>>>

###############################################################################
#file: html.pl #
# new subroutine #
# sub html_mass_mail_form #
###############################################################################

sub html_mass_mail_form {
#----------------------------------------------------------
my ($message) = $_[0];


&html_print_headers;

print qq|
<html><head><title>$html_title: Mass Mailer</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Mass Mailer</b></td></tr>
<tr><td>
<p><center><$font_title><b>
Mass Mailer
</b></font></center><br>
|;

if ($message) { print qq|There was a problem: $message|; }
print qq|
<$font>Fill in the subject of your message, the message you wish to send and the criteria
for the users to whom you wish to send the email.</font>
|;

print qq|
<form action="$db_script_url" method="POST">
<input type=hidden name="db" value="$db_setup">
<input type=hidden name="uid" value="$db_uid">
<table><tr><td align=right><$font>Subject:</font></td>
<td><input type=text name="subject" value="$in{'subject'}" size=40></td></tr>
<tr><td align=right><$font>Your message:</font></td>
<td><textarea name="emailmessage" cols=40 rows=10 wrap="virtual">$in{'emailmessage'}</TEXTAREA></td></tr>
</table>|;

&html_record_form(%in);

print qq|
<center>
<INPUT TYPE="SUBMIT" NAME="mass_mail" VALUE="Send Mail">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center>
</form>
|;

&html_footer;
print qq|</td></tr></table></body></html>|;
}

###############################################################################
#file: html.pl #
# new subroutine #
# sub html_mass_mail_success #
###############################################################################

sub html_mass_mail_success {
#-----------------------------------------------

my ($message) = $_[0];

&html_print_headers;

print qq|
<html><head><title>$html_title: Mass Mailing Successful</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Send an email</b></td></tr>
<tr><td><p><center><$font_title><b>
Mass Mailing Successful
</b></font></center><br>
|;

print qq|<$font>Your email message was sent to $message users.</font>|;

&html_footer;
print qq|</td></tr></table></body></html>|;
}
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
JP,
I was able to get the Mass Mailer to work and it pulls the email filed that is stated in the cfg file (in this case the 'ClientEmail".
However, the db file also contains up to 15 other email addresses (Vendor1Email, Vendor2Email, etc). I tried the following modification of the cfg file, placed * in the ClientEmail and the Vendor1Email but only received an email to the client.
# Field number or name of email field
$db_email_field = 'ClientEmail','Vendor1Email';


Is there another way to apporach this problem?

Chef Mars
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
This is why I ended up with problems. I was trying to put together several mods I wrote for the board and I got mixed up with my subroutine names.

I'll try to give you something that changes as little as possible of what you have.

First, you need to set the email field. This would go somewhere in your .cfg file:
Code:
# Fieldname that contains the email address of the user
$db_email_field = 'Email';


Then replace the following subroutine:
Code:
sub send_email {
# --------------------------------------------------------

my ($i,$message,@lines,$line,$count,%rec,$mail_count);

unless ($admin_email) { $message = "Admin email has not been entered in the .cfg file<BR>"; }
unless ($admin_email =~ /.+\@.+\..+/) { $message = "Admin email address is not in the correct format.<BR>"; }
unless ($in{'subject'}) { $message .= "You must fill in a subject for your message.<BR>"; }
unless ($in{'emailmessage'}) { $message .= "Your email message is empty.<BR>"; }
for ($i = 0; $i <= $#db_cols; $i++) {
if ($db_email_field eq $db_cols[$i]) {
$found = 1;
last;
}
}
if (!$found) {
$message .= "email field not found<BR>";
}
open (DB, "<$db_file_name") or &cgierr("error in mass_mail. unable to open database: $db_file_name.\nReason: $!");
@lines = <DB>;
close DB;
$in{'mh'} = $#lines + 1;
my ($status, @hits) = &query("view");
unless ($status eq 'ok') {
$message .= "$status<BR>";
}
if ($message) {
chomp($message);
&html_send_email_form($message);
return;
}
my ($numhits) = ($#hits+1) / ($#db_cols+1);
for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
if ($rec{$db_email_field} =~ /.+\@.+\..+/) {
open (MAIL, "$mailprog") || &cgierr("unable to open mail program");
print MAIL "To: $rec{$db_email_field}\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: $in{'subject'}\n\n";
print MAIL "-" x 75 . "\n\n";
print MAIL $in{'emailmessage'};
close (MAIL);
}
}
&html_send_email_success;
}

This doesn't count the number that were sent. That would require a change to the html file as well.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Mass Mailer Modification In reply to
JPDeni,
Thanks for staying with this porblem.
I did the sub rsend_email change an get the following error message:
There was a problem: no search terms specified
Fill in the subject of your email and the message you wish to send.


I have removed al of the Mass Email code.
What search term, beside the email address in the cfg file is it looking for?
Chef Mars
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
I had it set up that you would do a search in order to narrow down the number of emails being sent so it wouldn't overtax your system.

After

$in{'mh'} = $#lines + 1;

add

$in{$db_key} = "*";

That will send an email for every record in your database.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Mass Mailer Modification In reply to
JP,
Thank you once again for helping me with this problem.
Your generosity with your knowledge and time is humbling.

Regards,

Chef Mars
Quote Reply
Re: [chefmars] Mass Mailer Modification In reply to
You're welcome. :-) It's nice to be needed. :-D


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.