Random pause in-between mailing?

Joseph

Member
Is there a way to random pause for each email sent?

Right now there's an option of setting pause in terms of milliseconds in Server settings. The emailing is constant at each interval.

I'm looking at randomly pause between, say, 5 seconds to 60 seconds between each email sent.

Is there a way to do it?
 
Here's and example for sleeping randomly for 0 to 10 sec:
PHP:
// apps/init-custom.php
Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function(){
    sleep(rand(0, 10));
});
 
Thanks for the script. So for this script, it will add on a random seconds pause after the configured "Pause after send" in Server?

That means, in Backend->Server->Pause after send if I put "2000000", the above script will add another random X seconds to this "2000000" right?
 
Here's and example for sleeping randomly for 0 to 10 sec:
PHP:
// apps/init-custom.php
Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function(){
    sleep(rand(0, 10));
});
Sorry, for the above code, which file do I place that code? I can't find init-custom.php in /apps/, only init.php. Is it an additional file? Or add a code in the init.php?
 
This is how you do it if you want to only insert random pause for just a few servers.

Let's say, for servers having the id: 1, 5 and 10:
PHP:
Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $sent, $response, $status
){
    if (!empty($server) && in_array($server->server_id, [1, 5, 10])) {
        sleep(rand(0, 10));
    }
});

For all SMTP servers:
PHP:
Yii::app()->hooks->addAction('console_command_send_campaigns_after_send_to_subscriber', function($campaign, $subscriber, $customer, $server, $sent, $response, $status
){
    if (!empty($server) && stripos($server->type, 'smtp') !== false) {
        sleep(rand(0, 10));
    }
});
 
Back
Top