1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| #!/usr/bin/perl -w
use MIME::Lite;
#DO NOT TOUCH
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year=$year+1900;
$mon=$mon+1;
my $DATE=sprintf "%.4d-%.2d-%.2d",$year,$mon,$mday;
#A CONFIGURER
#
my $CSVFILE=$ARGV[0];
my $MSGFILE=$ARGV[1];
my $BOUNCED_FROM="adresse\@domaine.fr";
my $FROM="=?blablabla?= <welcome\@newsletter.test.envoi>";
my $SUBJECT="Mettre sujet!";
my $BADLOGFILE="destinataires.log.bad";
my $GOODLOGFILE="destinataires.log.good";
open(BADLOGFILE,">>$BADLOGFILE");
open(GOODLOGFILE,">>$GOODLOGFILE");
# my $mode = 0777;
# chmod oct($mode), '$BADLOGFILE';
#PARSE LES DATA DU CSV
my %data;
$i=0;$j=0;
open(FILEIN,$CSVFILE);
while(my $line=<FILEIN>) {
chomp $line;
@tmp=split(/\:\:/,$line);
foreach $t (@tmp) {
$data[$i][$j]=$t;
$j++;
}
$j=0;
$i++;
}
$myCount=$i;
close(FILEIN);
# print $data[lignes][colonnes]
#LIRE LE FICHIER MESSAGE
my $message;
open(FILEIN,$MSGFILE);
while($line=<FILEIN>) {
$message.=$line;
}
close(FILEIN);
#print "\U$data[0][0]\E";
$i=0;
my $firstname;
my $email;
while($i<$myCount) {
$email=$data[$i][0];
if($email =~ /[0-9a-zA-Z_]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,4}/) {
chomp($email);
#Substitute.
$content_message = $message;
$content_message =~ s/XXX_EMAIL/$email/g;
$content_message =~ s/XXX_email/$email/g;
#print $message;
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>$FROM,
To =>$email,
Subject =>$SUBJECT,
Type =>'multipart/alternative'
);
# $msg->add("Errors-To" => $BOUNCED_FROM);
# $msg->add("Envelope-From" => $BOUNCED_FROM);
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(
Type =>'text/html',
Data => $content_message
);
$msg->send;
print GOODLOGFILE "$email\n";
}
else {
print BADLOGFILE "$email\n";
}
$i++;
}
close(GOODLOGFILE);
close(BADLOGFILE); |
Partager