viewing paste mailing | Perl

Posted on the | Last edited on
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
#!/usr/bin/perl -w
 
use strict;
use Getopt::Long;
use Net::SMTP::SSL;
 
my %conf = (
    smtp => 'smtp.gmail.com',
    from => 'lightaisme at gmail.com',
    pwd => 'cmjmozyxukeikcme',
    intr => 0.2,
);
my %opt;
GetOptions(\%opt, "body=s", "list=s")  or die "Options: --body <file> --list <CSV adress>\n";
die "Please enter options \n" unless($opt{body} && $opt{list} );
 
open BODY,$opt{body} or die "can't read body $!\n";
my $body = join "", <BODY>;
close BODY;
 
print "Body = \n ".$body." \n End Body \n";
open LIST, $opt{list} or die "Can't read list: $!\n";
 
while(<LIST>) {
    chomp;
    my $adr = $_;
#    print "Cur adressse = $adr \n";
 
    my $smtp;
 
    if (not $smtp = Net::SMTP::SSL->new($conf{smtp},
                                Port => 465,
                                Debug => 1)) {
       die "Could not connect to server\n";
    }
    $smtp->auth($conf{from}, $conf{pwd})
       || die "Authentication failed!\n";
 
    $smtp->mail($conf{from})
      or die "Error: MAIL FROM\n";
    $smtp->to($adr)
      or die "Error: RCPT TO\n";
    $smtp->data()
      or die "Error: DATA\n";
    $smtp->datasend($body)
      or die "Can't send message\n";
    $smtp->dataend()
      or die "Error (DATA end)\n";
    $smtp->quit()
      or die "Error: QUIT\n";
    sleep $conf{intr};
}
close LIST;
 
print "Mailing finish \n";
Viewed 568 times, submitted by lighta.