Page 1 of 1

Error: [421 too many messages in this connection]

Posted: Mon Jan 14, 2008 9:02 pm
by bruno_mac
Hi!

I got this error when sending the emails to a list of clients from a database. Am I supposed to close and re-open the Swift connection after XX number of emails are sent out?
This is how I am sending the messages:

Code: Select all

 
while ($row = mysql_fetch_array ($result)){
    $recipient_id = $row['recipient_id'];
    $list_id = $row['list_id'];
 
    $replacements = array($row["recipient_email"] => array("{UNSUBSCRIBE_EMAIL}" => $row["recipient_email"], 
                                        "{LIST_ID}" => $row["list_id"], 
                                        "{FIRST_NAME}" => $row["recipient_first_name"], 
                                        "{LAST_NAME}" => $row["recipient_last_name"]));
    
    //Load the plugin with these replacements
    $swift->attachPlugin(new Swift_Plugin_Decorator($replacements), "decorator");
 
    //Replace content in the $parts, this will still affect $message due to the references
    //$htmlPart->setBody(str_replace("{UNSUBSCRIBE_EMAIL}", $row["recipient_email"], $html_body));
    //$textPart->setBody(str_replace("{UNSUBSCRIBE_EMAIL}", $row["recipient_email"], $text_body));
 
    //set the number of messages per minute
    $throttler->setEmailsPerMinute(100); 
    $swift->attachPlugin($throttler, "throttler");
 
    if ($swift->send($message, $row['recipient_email'], new Swift_Address($message_from_email, $message_from_name))){
            //echo "Sent";
            }
                else {echo "Failed";}
 
What is the problem with my sending? By the way, I got the error message exactly after sending 1000 emails out.

Thanks a lot for the help.

Re: Error: [421 too many messages in this connection]

Posted: Mon Jan 14, 2008 9:11 pm
by Chris Corbyn
Take a look at the AntiFlood plugin....

Re: Error: [421 too many messages in this connection]

Posted: Mon Jan 14, 2008 10:11 pm
by bruno_mac
Thanks. I completely forgot about that great plugin.

Should I set those plugins (anti-flood and throttler) inside my "while" loop of email addresses?

Re: Error: [421 too many messages in this connection]

Posted: Mon Jan 14, 2008 10:18 pm
by Chris Corbyn
bruno_mac wrote:Thanks. I completely forgot about that great plugin.

Should I set those plugins (anti-flood and throttler) inside my "while" loop of email addresses?
No, just set them before sending. Generally speaking when looping you want to do as little possible inside the loop otherwise you're running the same code thousands of times over ;)

Re: Error: [421 too many messages in this connection]

Posted: Mon Jan 14, 2008 10:50 pm
by bruno_mac
Thanks.
But on my code snippet above, I have all those plugins and settings inside my loop. This loops only goes through all the email addresses. So I should bring all those out of the loop?

Inside my loop then, I will only have the Replacement plugin, which takes a different value for each message and the actual sending. Is this correct?

Thanks a lot.
Bruno.

Re: Error: [421 too many messages in this connection]

Posted: Tue Jan 15, 2008 2:45 am
by Chris Corbyn
You should really be using batchSend() and putting the replacements plugin only once. What you're currently doing is a little wasteful. Take a look at the notes on "Sending to multiple recipients" and then again at the notes on the Decorator plugin in the wiki ;)