no from or to in Swift_Events_BeforeSendListener

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
n2breed
Forum Newbie
Posts: 3
Joined: Wed May 28, 2008 8:56 pm

no from or to in Swift_Events_BeforeSendListener

Post by n2breed »

Hey,

I'm writing a plugin that implements Swift_Events_BeforeSendListener to pipe $e->getMessage()->build()->readFull() to spamassassin but the headers are not complete and I need a snapshot of the final message to score it properly.

During execution of beforeSendPerformed() the To, From and Message ID are blank:

Code: Select all

 
To: 
From: 
Subject: My stuff
Date: Thu, 29 May 2008 12:01:30 +1000
X-LibVersion: 3.3.2
MIME-Version: 1.0
etc.
 
Is there way to get a full render of the message + headers before it's sent?

Cheers..!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: no from or to in Swift_Events_BeforeSendListener

Post by Chris Corbyn »

Ah yes, that's a problem really. Swift adds those headers immediately before sending the message, but apparently not before the beforeSendPerformed() method is used. It'd require some modification of the send() method inside the Swift class to change that.
n2breed
Forum Newbie
Posts: 3
Joined: Wed May 28, 2008 8:56 pm

Re: no from or to in Swift_Events_BeforeSendListener

Post by n2breed »

Right ! well I had a look at that.. it's just before the headers are set! So close yet so far .. Maybe I'll do something external to swift for this bit .. However the manual needs an update near:
"BeforeSendListener is run before the message gets sent. You will know who the recipients are and what the message is at this stage, ... and so on .."

http://www.swiftmailer.org/wikidocs/v3/ ... esendevent
Thanks heaps for your help.. :wink:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: no from or to in Swift_Events_BeforeSendListener

Post by Chris Corbyn »

n2breed wrote:Right ! well I had a look at that.. it's just before the headers are set! So close yet so far .. Maybe I'll do something external to swift for this bit .. However the manual needs an update near:
"BeforeSendListener is run before the message gets sent. You will know who the recipients are and what the message is at this stage, ... and so on .."

http://www.swiftmailer.org/wikidocs/v3/ ... esendevent
Thanks heaps for your help.. :wink:
$event->getRecipients();

That returns a RecipientList instance.
n2breed
Forum Newbie
Posts: 3
Joined: Wed May 28, 2008 8:56 pm

Re: no from or to in Swift_Events_BeforeSendListener

Post by n2breed »

Chris Corbyn wrote:
$event->getRecipients();

That returns a RecipientList instance.
And then how would I render a raw message from there?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: no from or to in Swift_Events_BeforeSendListener

Post by Chris Corbyn »

Code: Select all

$message->setTo($recipients->getTo());
// etc etc...
It's not very elegant though since once you've done that you then need to setTo(null) before the end of the method otherwise Swift will not do it's own natural set of replacements in the Headers.
Post Reply