#!/usr/bin/perl -w ###### my $orig_email = "megabelles\@yahoo.ca"; my $orig_name = "Mathilde"; my $source_file = "mega-final.html"; my $sql_query = "select mails from mails_xponsor_new group by mails order by id asc LIMIT 110055,10011"; my $subject = "Mega Belle !"; ###### use DBI; use strict; #my $dbh = DBI->connect("DBI:mysql:database=martial;host=62.4.84.47", # "8447","4ngaGThrE", {'RaiseError' => 1}); #my $dbh = DBI->connect("DBI:mysql:database=webxmailing;host=localhost", # "root","#th\@jw73p", {'RaiseError' => 1}); my $dbh = DBI->connect("DBI:mysql:database=martial;host=localhost", "root","S0OLO4WV0", {'RaiseError' => 1}); #my $dbh = DBI->connect("DBI:mysql:database=mailing;host=localhost", #"root","5CQ8e8qnwb", {'RaiseError' => 1}); ## Select request my $sth = $dbh->prepare($sql_query); $sth->execute(); ## process list my %emails; while(my $ref = $sth->fetchrow_arrayref()) { $emails{$$ref[0]} = 1; } ## open email my $emailcontent = ""; open EMAIL, "< $source_file"; while(){ $emailcontent .= $_; } close EMAIL; ## reset for the test a virer ## %emails = ("garfield_the_freecat\@hotmail.com",1); ## %emails = ("mptlse2\@wanadoo.fr",1); my @totalmails = (keys %emails); my $mailcount = @totalmails; print "Voulez allez envoyer $mailcount emails... Appuyez sur CTRL+C pour interrompre, entree pour continuer Pour voir la progression : tail -f log.txt Pour interrompre en cours : kill -9 \`cat mailer.pid\` "; my $tmp = ; print "Going to Daemon ...\n"; defined (my $pid = fork) or die "Can't fork: $!"; if ($pid) { exit; } else { # redirect stdin/stdout to nothing require 'POSIX.pm'; &POSIX::setsid or die "Can't start a new session: $!"; open STDOUT,'>>log.txt' or die "ERROR: Redirecting STDOUT to /dev/null: $!"; open STDERR,'>>log.txt' or die "ERROR: Redirecting STDOUT to /dev/null: $!"; open STDIN, 'mailer.pid"; print PID $$; close PID; ## Send email my $count = 0; print "Starting send... PID $$ ... $mailcount mails!!\n"; foreach my $email (keys %emails) { my $emailcpy = $emailcontent; $emailcpy =~ s/%email%/$email/g; $count++; print "($count/$mailcount) - Starting send to $email... "; open SENDMAIL, "|/usr/sbin/sendmail -t -i -f$orig_email"; # start headers print SENDMAIL "From: \"$orig_name\" <$orig_email>\n"; print SENDMAIL "To: $email <$email>\n"; print SENDMAIL "MIME-Version: 1.0\n"; print SENDMAIL "Content-Type: text/html\n"; print SENDMAIL "Subject: $subject\n"; # end headers print SENDMAIL "\n"; print SENDMAIL $emailcpy; close SENDMAIL; print "Done.\n"; } print "finished send - end.\n\n"; unlink "mailer.pid";