in reply to sending bulk emails in a specified time

ok this is what i have....
my %mail = ( To => $email, From => $adminemail, smtp => $smtp, port => $port, Subject => $subject, Message => $body, ); sendmail(%mail) or die( 'Couldnt send mail:', Mail::Sendmail->erro +r() ); sleep 1;
but i do not know where to go from here, how i can specify a certain number of emails in a specific time.

thanks

edited by dws to add <code> tags

Replies are listed 'Best First'.
Re: Re: sending bulk emails in a specified time
by gellyfish (Monsignor) on Feb 03, 2002 at 14:04 UTC

    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\

      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\

Re: Re: sending bulk emails in a specified time
by Ryszard (Priest) on Feb 04, 2002 at 01:07 UTC
    While youre at it, why not use <code> tags. It makes you code easier to read.