[Vmail-discuss] mass mail
Odhiambo Washington
wash@wananchi.com
Wed, 27 Nov 2002 13:26:26 +0300
--A6N2fC+uXW/VQSAv
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
* Chris Lightfoot <chris@ex-parrot.com> [20021119 19:04]: wrote:
> On Tue, Nov 19, 2002 at 05:01:30PM +0100, Franz Georg K=F6hler wrote:
> > On Tue, Nov 19, 2002 at 09:56:56AM -0600, phiber <phiber@phiber.linuxgo=
d.net> wrote:
> > > what would be the best way to send all users of all virtual host a ma=
il?=20
> >=20
> > A mailing list manager: http://www.list.org/ .
I am not sure Mailman supports MySQL based lists. I use it here, but for
mailing all users, (system users + sql-based users) I got our in-house
programmer to craft out a script to do it. I am attaching the script
here for the benefit of anyone who needs it.
-Wash
--=20
Odhiambo Washington <wash@wananchi.com> "The box said 'Requires
Wananchi Online Ltd. www.wananchi.com Windows 95, NT, or better,'
Tel: +254 2 313985-9 +254 2 313922 so I installed FreeBSD." =20
GSM: +254 72 743223 +254 733 744121 This sig is McQ! :-)
If a President doesn't do it to his wife, he'll do it to his country.
--A6N2fC+uXW/VQSAv
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=mailall
#!/usr/bin/perl5
sub GotSig {
print "Caught one of signals INT, QUIT. Exiting...\n";
exit;
}
$SIG{'INT'} = "GotSig";
system "/usr/bin/clear";
($< ==0) || die "You must run this program as root!\n";
print "Please select the username for the return-path of this mass mail:\n\n";
print "1. admin\n";
print "2. operations\n";
print "3. cs\n";
print "4. OTHER username\n\n";
$ans=<>;
chomp $ans;
label: {
$from = "administrateur", last label if ($ans == 1);
$from = "operations", last label if ($ans == 2);
$from = "support", last label if ($ans == 3);
print "Enter username:"; $from = <>; chop $from, last label if ($ans == 4);
$from = "admin"; print "Incorrect value entered. Using admin as default\n";
}
print "\nFrom user: $from\n";
print "Press <RETURN> to edit message";
$junk=<STDIN>;
# Allow editing of message using pico
$tempfile="/tmp/massmail.$$";
# Make a template
open (OUT,">$tempfile");
print OUT "From: $from\@DOMAIN.TLD\n";
print OUT "To: All Users\n";
print OUT "Subject: \n\n";
print OUT "Message body here. Make sure there's a blank line between
header and body\n\n";
close (OUT);
# Now edit it
$ans="e";
while ($ans ne "n") {
if ($ans eq "e" || $ans eq "E") {
system "/usr/local/bin/pico -t -z $tempfile";
}
system "clear";
print "I am now about to mass mail this message to ALL users:\n\n";
print "(G)o ahead\n\n(N)o way!\n\n(E)dit the message again\n\n";
$ans=<>;
chomp $ans;
if ($ans eq "n" || $ans eq "N") { exit;}
if ($ans eq "g" || $ans eq "G") { last; }
}
while (($account, $bla, $uid) = getpwent())
{
if ( $uid > 100 && $uid < 32000 ) {
push (@userlist, $account);
}
}
print "Would you like to include domainplus users ? Y/N";
if(<STDIN> eq lc("Y")) {
use DBI;
$dbh = DBI->connect("DBI:mysql:DBNAME:HOSTNAME","DBUSERNAME","DBPASS") || die("can't connect to mysql");
$query = $dbh->prepare("select concat(local_part,'\@',domain_name) as user from popbox");
$query->execute || die("there is error in query");
while($user = $query->fetchrow) {
#print "sql user : ".$user."\n";
push(@userlist,$user);
}
$query->finish;
$dbh->disconnect;
}
print "Starting mass mail....\n";
#system
foreach $user (@userlist) {
$i++;
$total = @userlist;
$tmp = @tmpuserlist;
push(@tmpuserlist,$user);
if($i==200) {
system "/usr/local/sbin/exim -i -f $from @tmpuserlist < $tempfile &";
undef(@tmpuserlist);
$i=0;
}
}
if($i<200) {
system "/usr/local/sbin/exim -i -f $from @tmpuserlist < $tempfile &";
}
print "Done.\n";
END {
print "Removing temporary file...\n";
unlink $tempfile;
}
--A6N2fC+uXW/VQSAv--