in reply to Re: sending bulk emails in a specified time
in thread sending bulk emails in a specified time

Of course we are going to need a note from your mother that you aren't going to do any spamming ;-}

The simplest way to do this would be to have a counter in your loop so that you could have something like:

... my $number_of_emails_per_minute = 100; .. my $time = time(); my $count = 0; while(WHEREVER YOUR ADDRESSES ARE COMING FROM) { # do whatever you do to send mail $count++; if ( $count == $number_of_emails_per_minute ) { my $time_left = 60 - ( time() - $time ); sleep $time_left; $time = time(); $count = 0; } }

I haven't got Mail::Sendmail on here at the moment so I can't make a proper example I'm afraid

/J\

Replies are listed 'Best First'.
Re: sending bulk emails in a specified time
by fullyloaded (Initiate) on Feb 03, 2002 at 23:19 UTC
    lol nah im not doing it for spam purposes :) cheers for the code, it works a treat except for one problem, im running my perl script from a browser so the browser is sitting there processing the emails for a couple of minutes before the perl script can carry on and redirect the page, how do i over come this, i want the page to redirect and have the emails sent in the background, so i can continue to use the page. i also want to try and aviod timeouts if possible, have u got any suggestions? thanks i appreciate your help :)

      If your webserver is running an OS that supports it then you could use fork something like :

      #!/usr/bin/perl -w use CGI qw(redirect); use strict; $| = 1; if (my $pid = fork) { print redirect 'http://www.whatever.com'; } else { close STDIN; close STDOUT; # do your mail sending here }

      Closing STDIN and STDOUT is important so the server knows to close the connection to the browser

      /J\

        ok thanks heaps but im unclear about a few things, i dont quite get how the code above works, u set $pid = fork, making the if statement true, so the broswer redirects when the if statement gets executed, how will the else statement that sends the emails ever get executed? i did run this code in my script and it appears to work, however im not 100% sure the fork was created, is there little test i can do to see if the fork was created and the fork actually send the emails and not the script itself that sent the emails? thanks