-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added getMessage method to access Swift_Message #9
base: master
Are you sure you want to change the base?
Conversation
Needed to store the message ID separately as Swiftmailer changes the ID on the message object after send.
I've slightly updated this as I noticed the MessageID recorded was different to the one received on email. This is because SwiftMailer changes it once sent. There is now a new method called getMessageId() which stores the ID before the send. It allows you to access it using the following update to the code above. $message_id = null;
Mailer::applyFilter('deliver', function($self, $params, $chain) use (&$message_id) {
extract($params);
$result = $chain->next($self, $params, $chain);
$message_id = $transport->getMessageId();
return $result;
}); |
Why not have |
@markwilde not sure if i fully understand everything, but by looking at your code you set the |
@eLod I needed to collect the message ID before the send in SwiftMailer because it seems to generate the message id on the object before send, and once sent it changes it to a new id. I personally think that @DavidPersson idea of setting the message id on return for each adapter would probably be better for now on each adapter as li3_mailer needs to have a standard return from the send function so it's predictable what is being returned. Maybe even the li3_mailer Message object being returned with all the information would be better? |
@markwilde what is changing the id? i don't think it's a good idea that the adapters return the message id, as you said, the message itself would be better (so you can look at the message id and any other attribute as well). that said the return value of the transport/send is still important, how else would you know if your message got sent actually (or know what error happened, if the return value indicates that, etc.)? the adapter could return you other information as well. so i would go with a composite return value. |
@eLod I think it is SwiftMailer and from what I could find it's to do with how it handles bulk message sending. Maybe the li3_mailer message object could contain attributes for error handling to that similar to how models handle errors? That way you could interrogate the message object to find out if it's been sent etc. |
I've added a method for read access to the Swift_Message instance. I needed it so I could reach into the transport adapter and pick out the Message-ID from the message once it had been delivered. Might be useful if there are any other headers etc to read once message has been sent.
I then was able to use the following to get what I needed from my controller once I'd delivered the message: