Page 2 of 2
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 3:50 pm
by Chris Corbyn
I'll post back here in a sec. This code is not correct if what you want is the Message-ID. It's also not correct for v4 (no $evt->getRecipients() method).
Something has just dawned on me however. If these recipients are all part of a batchSend() they will all have the same Message-ID (because they all get the same message). I think this should be considered a bug and the correct behaviour should be to regenerate the message ID after each send. I'll make this change today.
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 3:53 pm
by Chris Corbyn
Correct code:
Code: Select all
class Swift_Plugins_Return_id implements Swift_Events_SendListener {
private $messageIds=array();
public function returnId(Swift_Events_SendEvent $e) {
return $this->messageIds;
}
/**
* Not used.
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt)
{
}
public function sendPerformed(Swift_Events_SendEvent $evt)
{
$message = $evt->getMessage();
$this->messageIds[] = $message->getId();
}
}
But like I say, if these are all in one single call to batchSend() you'll find that all the IDs are the same. I can fix this so easily but you may have to wait a couple of hours for the next release.
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 3:54 pm
by ddh
ok, just to add: I'm using send() and not batchsend() at the moment.
edit: I see that you already posted the code. Great, thanks, you're fast! I'll give it a try right away.
David
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 3:59 pm
by xdecock
yup, message-id must be reset on each body / header change
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 4:08 pm
by ddh
Still no luck...
Right now I get this error again:
Code: Select all
Catchable fatal error: Argument 1 passed to Swift_Plugins_Return_id::returnId() must be an instance of Swift_Events_SendEvent, none given, called in /home/.../Swift-4.0.0-b4/examples/basics2.php on line 48 and defined in /home/.../Swift-4.0.0-b4/lib/classes/Swift/Plugins/ReturnIdPlugin.php on line 8
How should I pass the instance of Swift_events_SendEvent to Swift_Plugins_Return_id::returnId?
To recollect, this is the code I now use:
The plugin:
Code: Select all
class Swift_Plugins_Return_id implements Swift_Events_SendListener {
//$this->messageIds=array();
private $messageIds = array();
public function returnId(Swift_Events_SendEvent $e) {
return $this->messageIds;
}
/**
* Not used.
*/
public function beforeSendPerformed(Swift_Events_SendEvent $evt)
{
}
public function sendPerformed(Swift_Events_SendEvent $evt) {
$message = $evt->getMessage();
$this->messageIds[] = $message->getId();
}
}
And the sending code:
Code: Select all
$mailer = Swift_Mailer::newInstance($transport);
//Create a message
$message = Swift_Message::newInstance('A basic message')
->setBody("the body
", 'text/plain')
->setTo(...)
->setFrom(...)
;
require "../lib/classes/Swift/Plugins/ReturnIdPlugin.php";
$mailer->registerPlugin($returnPlugin=new Swift_Plugins_Return_id());
//Send it
if ($mailer->send($message))
{
echo "Message sent!";
echo "\nId:" . $returnPlugin->returnId();
}
else
{
echo "Error sending";
}
Thanks again!
David
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 4:13 pm
by Chris Corbyn
xdecock wrote:yup, message-id must be reset on each body / header change
I just implemented it

After each send() inside any of the transports $message->generateId() is invoked. Seemed like the least expensive and most foolproof way to do it
Sorry, this method declaration:
Code: Select all
public function returnId(Swift_Events_SendEvent $e) {
//should be
public function returnId() {
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 4:13 pm
by xdecock
remove the bold section in the code :
returnId(Swift_Events_SendEvent $e) {
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 4:16 pm
by xdecock
Chris Corbyn wrote:xdecock wrote:yup, message-id must be reset on each body / header change
I just implemented it

After each send() inside any of the transports $message->generateId() is invoked. Seemed like the least expensive and most foolproof way to do it
Yup Safe route
Re: Tracking batchSend
Posted: Tue Feb 03, 2009 4:18 pm
by ddh
Great, this works!!!!!!
Thank you both very much!
Cheers, David