Insert perl timer

Asked

Viewed 50 times

3

I need to put a timer on that perl below:

It works by firing email followed to the end of the mailing list.

Example if the list has 1 thousand emails it shoots email by email until finished.

I’d like to put a timer on that code

EX: Fire 500 emails every 30 seconds. Would it be possible ? I appreciate the attention already.

Below is the code or in the https://pastebin.com/nj8bYyZ8

#!/usr/local/bin/perl
#by IV ' lost
use MIME::Base64;
$ARGC=@ARGV;

if ($ARGC !=4) {
  printf "$0 <mailist> <remetente> <assunto> <fake.htm>\n\n";
 exit(1);
}

$sendmail = '/usr/sbin/sendmail';

$sender = $ARGV[1];

$subject = $ARGV[2];

$efile = $ARGV[0];

$emar = $ARGV[0];

open(FOO, $ARGV[3]);

@foo = <FOO>;

open (BANDFIT, "$emar") || die "Can't Open $emar";

$cont=0;

while(<BANDFIT>)        {
($ID,
 $options) = split(/\|/,$_);
chop($options);
  foreach ($ID) {
$r2 = int(rand(99));
$r3 = int(rand(999));
$r4 = int(rand(9999));
$r5 = int(rand(99999));
$r6 = int(rand(999999));
$r7 = int(rand(9999999));
$r8 = int(rand(99999999));
$r9 = int(rand(999999999));
$recipient = $ID;
$corpox = join("\n", @foo);
$corpox =~ s/%email%/$ID/g;
$corpox =~ s/%rand1%/$r1/g;
$corpox =~ s/%rand2%/$r2/g;
$corpox =~ s/%rand3%/$r3/g;
$corpox =~ s/%rand4%/$r4/g;
$corpox =~ s/%rand5%/$r5/g;
$corpox =~ s/%rand6%/$r6/g;
$corpox =~ s/%rand7%/$r7/g;
$corpox =~ s/%rand8%/$r8/g;
$corpox =~ s/%rand9%/$r9/g;
$corpo = encode_base64($corpox);

$subject =~ s/%email%/$ID/g;
$subject =~ s/%rand1%/$r1/g;
$subject =~ s/%rand2%/$r2/g;
$subject =~ s/%rand3%/$r3/g;
$subject =~ s/%rand4%/$r4/g;
$subject =~ s/%rand5%/$r5/g;
$subject =~ s/%rand6%/$r6/g;
$subject =~ s/%rand7%/$r7/g;
$subject =~ s/%rand8%/$r8/g;
$subject =~ s/%rand9%/$r9/g;

$sender =~ s/%rand4%/$r4/g;

open (SENDMAIL, "| $sendmail -t");
print SENDMAIL "MIME-Version: 1.0\n";
print SENDMAIL "Content-type:  text/html; charset=UTF-8\n";
print SENDMAIL "Content-Transfer-Encoding: base64\n";
#print SENDMAIL "$mailtype\n";
print SENDMAIL "Subject: $subject\n";
print SENDMAIL "From: $sender\n";
print SENDMAIL "To: $recipient\n";
print SENDMAIL "$corpo\n\n";
close (SENDMAIL);

$cont=$cont+1;
printf "$cont * Enviado para > $recipient";

}

}

close(BANDFIT);

1 answer

0

Miguel, If I understand correctly, you intend to take breaks, (not to saturate the system?).

If so, try something like putting a little sleep(x) in each shipment ( x in seconds),

#...ciclo de envio{
# ...enviar mail
       sleep(2);
#...}

or a large Sleep at the end of every 500

#...ciclo de envio
#...  enviar mail
      $cont=$cont+1;
      printf "$cont * Enviado para > $recipient";
      sleep(30) if $cont % 500 == 0;
#...

Finally consider using Mail::Sender

 use Mail::Sender;
 $sender = new Mail::Sender {smtp => 'mail.yourdom.com', from => '[email protected]'};
 $sender->MailFile({to => '[email protected]',
      subject => 'Here is the file',
      msg => "I'm sending you the list you wanted.",
      file => 'filename.txt'});
  • Could Joao give the example in the code ? please give it wrong here.

  • Where is the error? --> join line sleep(30) if $cont % 500 == 0; after the printf?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.