Switching SMTP server

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
StealthPhp
Forum Newbie
Posts: 3
Joined: Thu Sep 13, 2007 5:27 pm

Switching SMTP server

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

StealthPhp
Forum Newbie
Posts: 3
Joined: Thu Sep 13, 2007 5:27 pm

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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);
StealthPhp
Forum Newbie
Posts: 3
Joined: Thu Sep 13, 2007 5:27 pm

Post by StealthPhp »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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) ;)
Post Reply