Gossamer Forum
Home : Products : DBMan : Customization :

Admin bulk email to all

Quote Reply
Admin bulk email to all
Our user need input email, how admin can send bulk email to all member in admin login?

Thx


------------------
Quote Reply
Re: Admin bulk email to all In reply to
I suppose you'd need to make two more subroutines, one for the form which the admin would use to write the message (in html.pl) and one to pull the email addresses out and send the message to everyone (in db.cgi).

I'll put it on my list to think about how to do it and I'll get back to you if I come up with the code.

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





Quote Reply
Re: Admin bulk email to all In reply to
Okay. Here's what I came up with. It does not do any error-checking to make sure the email address is correct.

In default.cfg add
Code:
# Your email address. Be sure to leave in the \ before the @
$admin_email = "you\@server.com";
# Email program on your system -- leave the flags as they are so any errors will be caught
$mailprog = "|/usr/sbin/sendmail -t -oeq";
# Field number of email field
$db_email_field = 4;

Change the above values to match your system and your database.

In db.cgi, sub main, in the midst of all the other "elsif" statements, add

Code:
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:
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 email. unable to open db file: $db_file_name.\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_decode($line);
push(@email_list,$data[$db_email_field]);
}

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;
}

In html.pl add the following two subroutines:

Code:
sub html_send_email_form {
#--------------------------------
my ($message) = $_[0];
&html_print_headers;
# <-- top of page formatting -->
print qq|
<html><head><title>$html_title: Send an email</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td 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>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">
<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" width=40 height=10>$in{'emailmessage'}</textarea></td></tr>
</table>
<center>
<INPUT TYPE="SUBMIT" NAME="send_email" VALUE="Send Email">
<INPUT TYPE="RESET" VALUE="Reset Form">
</center>
</form>
|;
# <-- 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|
<html><head><title>$html_title: Send an email</title></head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500 align=center valign=top>
<tr><td 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>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></body></html>|;
}

In html.pl, sub html_footer, add the following line:

Code:
print qq!| <A HREF="$db_script_link_url&send_email_form=1">Send mass mailing</A> ! if ($per_admin);

I have tested this for syntax errors, but that's all. Seems like it would work.

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





Quote Reply
Re: Admin bulk email to all In reply to
I try it first

Thx



------------------
Quote Reply
Re: Admin bulk email to all In reply to
JPD, wouldn't there be some problems with server timeout, for a large bulk mailings ?!?
Quote Reply
Re: Admin bulk email to all In reply to
Could be. I don't know. I haven't tried it. I'm just pretty sure the Perl will work.

If there's a problem, please let me know.


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





Quote Reply
Re: Admin bulk email to all In reply to
Wow, Great mod...
Only one thing, I found out, that the message goes to all owners of records in the DB. I have owners of more than one record, so they will have unneccesary more than one message. Is it possible to send just one message to owners of more records, maybe take the list of emailadresses out of the PW file, or something???
Thanks in advance.

Greetings,
--------
Mart.
Quote Reply
Re: Admin bulk email to all In reply to
If you have a problem with timeouts because you're sending to too many addresses, you could use BCC: instead of To: when you're mailing, placing all or batches of addresses in there.

adam
Quote Reply
Re: Admin bulk email to all In reply to
Thanks, but thats not what I mean, if I understand you good.
When I use BCC, all the adresses came in the mail to everyone I sent.
I think the emailadresses must be taken out of the pwfile, only I don't know how....

Greetings,
----------
Mart
Quote Reply
Re: Admin bulk email to all In reply to
Mart, instead of

Code:
open (DB, "<$db_file_name") or &cgierr("error in send email. unable to open db file: $db_file_name.\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_decode($line);
push(@email_list,$data[$db_email_field]);
}

use

Code:
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]);
}

Adam was referring to the question about whether the server would time out, not your question about using the password file.

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





Quote Reply
Re: Admin bulk email to all In reply to
A quick note and maybe a laugh on scripting email routines.

Be very careful!

When I first experimented with email routines I accidentally placed the routine in a never ending loop that sent out about 12,000 emails before I figured out what was going on. Luckily I sent them to myself but I crashed my hosts server as well as my isp's mail server. Needless to say neither were too happy with Mike!

Thought that you might get a chuckle out of that. So just be careful of your coding.

Mike
Quote Reply
Re: [JPDeni] Admin bulk email to all In reply to
I have sucessfully implmented your "Admin bulk email to all" code.
I have been trying to blend it with your "forward record" mod so that each email is personalized with an old fashioned "inside address" that contains the recipient's name, company name etc. However I cannot quite get it to pull the respective records.

Can you help?

Would you like me to post what I have done so far?

Respectfully,

Chef Mars