[bglug] mail

enzo enzo.arlati@libero.it
Mar 26 Gen 2010 20:50:45 CET


Ti giro questo programma perl che dovrebbe fare al caso.
Lo usi passando l' indirizzo del destinatatrio, il numero dei messaggi
ed il soggetto della e-mail.
Poi lui si traveste un pochino, cambiando i dati di provenienza ( utile
per ricevere in casella e-mail direttamente da S. Lucia da mostrare ai
figli ).

[enzo@enzo6 mail]$ ./test.pl enzo.arlati@libero.it  7 "messaggio di prova"
[2010.1.26 20:45:21] [*MYLOG:*5475*]  send msg to    times  
[2010.1.26 20:45:21] [*MYLOG:*5475*] SEND-MSG PARAM: from:
bill.gates@microsoft.com
 to: enzo.arlati@libero.it
 subject: messaggio di prova
 count: 7
 
[2010.1.26 20:45:21] [*MYLOG:*5475*] MESSAGE:  messaggio di prova num.
0  ( data: Tue Jan 26 20:45:21 2010 ) 
............ 
[2010.1.26 20:45:51] [*MYLOG:*5475*] MESSAGE:  messaggio di prova num.
6  ( data: Tue Jan 26 20:45:51 2010 ) 
 
[enzo@enzo6 mail]$




#!/usr/bin/perl
# ------------------------------------------
use Mail::Sender;
use strict;

# !"#$%&'()*+,-./0123456789:;<=>?@ [\]^_` {|}~

my ( $to , $count );
my ( $from, $fake_from, $bcc, $cc, $subject, $message, $sender );
my ( $idx, $stmp, $mydate, $subject_tmp  );
my ( @ll );
my $fname = 'file.txt';

my $log_filename = "$0.log";

mylog( " send msg to $to  $count times ");

$from      = 'bill.gates@microsoft.com';
$fake_from = 'sopra.la.panca@la.capra.canta';
$to        = $ARGV[0] || 'bill.gates@microsoft.com';
$count     = $ARGV[1] || 1;
$subject   = $ARGV[2] || "MAILATORE PERPETUO";
$cc        = '';
$bcc       = '';


open F, "$fname" or die "Non posso leggere il file $fname ( $! ) \n";
@ll = <F>;
close F;
chomp @ll;

mylog(  "SEND-MSG PARAM: from: $from \n to: $to \n subject: $subject \n
count: $count \n\n" );

$message = join( "\n", @ll );


for( $idx = 0; $idx < $count; $idx++ )
{
   $mydate = localtime(time());
   $subject_tmp = " $subject num. $idx  ( data: $mydate ) ";
   mylog(  "MESSAGE: $subject_tmp \n" );



   $sender = new Mail::Sender( { smtp => 'mail.libero.it', from => $from } )
                                    or die "Error creating Mail-Sender
$! \n";

   $sender->MailMsg({from => $from,
                      fake_from => $fake_from,
                      to => $to,
                      cc => $cc,
                      bcc => $bcc,
                      subject => $subject_tmp,
                      priotity => 1,
                      confirm => "delivery: napoleone.buonaparte.$to",
                      debug => 'sender-mailmsg.log',
                      msg => $message  })
          or die "sender->mail failed ($!) \n " . $sender->{'error'} .
".\n\n";


}



# =============================================
# SUBROUTINES
# =============================================
sub mylog
{
 my ($strmsg) = @_;
 my ($stmp, $msg, $sec, $min, $hour, $mday, $mon, $year, $wday, $yday,
$isdst);
 
 # ---------------------------------------------------------
 if (!defined($log_filename)) { return }
 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime(time);
 $year += 1900;
 $mon  += 1;
 
 # ---------------------------------------------------------
 my (@ll);
 my ($funName);
 
 # ---------------------------------------------------------
 @ll = caller(2);
 if (@ll)
 {
  $funName = (@ll)[3];
 }
 else
 {
  @ll = caller(1);
  if (@ll)
  {
   $funName = "-+-:" . (@ll)[3];
  }
 } ## end else [ if (@ll)
     # ---------------------------------------------------------
 if (!defined $funName) { $funName = "MYLOG:"; }
 
 # ---------------------------------------------------------
 open(F,      ">>$log_filename")
   or open(F, ">$log_filename")
   or warn "..Non posso aprire il file $log_filename ($!) \n";
 
 $msg = "[$year.$mon.$mday $hour:$min:$sec] [*$funName*$$*] $strmsg ";
 print F "$msg \n";
 warn "$msg \n";
 
 close F;
} ## end sub mylog



-- 
REPLY TO: perl -e 'print qq^VVCWCQJUVD00YQVWKVBPG^^qq^3898m08970Yp584299l93^ '
WEB: http://earlati.freehostia.com/



Maggiori informazioni sulla lista bglug