Page 1 of 1
Switching SMTP server
Posted: Thu Sep 13, 2007 5:31 pm
by StealthPhp
Hi Everyone,
I am using SwiftMailer to send our company newsletters. Because there are 25,000+ members in the list, I prefer switching between three SMTP servers (different IP addresses) while sending.
So, I start looping those 25,000 members and use the first SMTP server. The question is, how can I switch to second and third SMTP servers within the recipient loop without loosing any defined variables in the Swift object?
Thanks for your help.
Posted: Fri Sep 14, 2007 1:20 am
by Chris Corbyn
Posted: Sat Sep 15, 2007 5:08 pm
by StealthPhp
Thanks, I checked out rotator plug-in. It seems to be the right choice, but what I wonder is how to rotate SMTP servers at specific intervals. Instead of changing SMTP server on every email, I want to change it every 5,000 emails (just an example).
For example, I have 4 SMTP serves:
SMTP #1
SMTP #2
SMTP #3
SMTP #4
I want to switch SMTP servers on different intervals for each SMTP server. For example,
Send 1000 emails with SMTP #1 and then switch to #2
Send 5000 emails with SMTP #2 and then switch to #3
Send 2500 emails with SMTP #3 and then switch to #4
Send 7000 emails with SMTP #4 and then switch to #1...
Can I do this with Rotator plug-in?
Thanks for your help.
Posted: Sun Sep 16, 2007 10:22 am
by Chris Corbyn
You can set an interval, but you can't make it send different amounts through different servers. The Rotator connection depends upon a plugin called ConnectionRotator. The plugin just "listens" for SendEvent messages and invokes a rotation method in the connection.
You can adjust the threshold (default is 1) by calling:
Code: Select all
$swift =& new Swift(new Swift_Connection_Rotator(..... ));
$rotatorPlugin =& $swift->getPlugin("_ROTATOR"); //I know I know
$rotatorPlugin->setThreshold(5000);
Posted: Wed Sep 26, 2007 7:52 am
by StealthPhp
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Thanks for your kind reply. I implemented your suggestions and now I have another problem.
I have three SMTP servers but when I try to send 8 emails with 3 SMTP servers using rotator plug-in, after sending the first email, the following error message is displayed on screen:
Code: Select all
Connection problem: There was a problem reading line 1 of an SMTP response. The response so far was:
[]. It appears the connection has died without saying goodbye to us! Too many emails in one go perhaps? (fsockopen: #0)
What can be the problem?
The code is:
Code: Select all
include_once($this->SwiftMailerPath.'/Swift/Connection/SMTP.php');
include_once($this->SwiftMailerPath.'/Swift/Connection/Rotator.php');
$ArrayConnections = array();
$TMPCounter = 0;
foreach ($this->SMTPHost as $EachHost)
{
unset($Connection);
$Connection =& new Swift_Connection_SMTP($this->SMTPHost[$TMPCounter], $this->SMTPPort[$TMPCounter], ($this->SMTPSSL[$TMPCounter] == true ? Swift_Connection_SMTP::ENC_TLS : ''));
$Connection->setUsername = $this->SMTPUsername[$TMPCounter];
$Connection->setPassword = $this->SMTPPassword[$TMPCounter];
$Connection->setTimeout = $this->TimeOut[$TMPCounter];
$ArrayConnections[] =& $Connection;
$TMPCounter++;
}
$this->ObjectConnection =& new Swift_Connection_Rotator($ArrayConnections);
$this->ObjectSwift =& new Swift($this->ObjectConnection);
$ObjectRotatorPlugin =& $this->ObjectSwift->getPlugin("_ROTATOR");
$ObjectRotatorPlugin->setThreshold(5000);
Thanks.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Wed Sep 26, 2007 6:44 pm
by Chris Corbyn
This could well be a bug. I've never real-world tested changing the threshold before. I'll have a coser look in the morning (before I lose my internet)
