laravel-postal
laravel-postal copied to clipboard
Headers are not passed to Postal Message
Hey,
maybe I setup something wrong, but with the logEmailAgainstModel
method set and the 'postal.enable.emaillogging'
value set to true I do not get the notifiable_class
and notifiable_id
headers passed to Postal.
On inspection they do get set on the underlying Swift_Message
instance, but get lost during the transformation to a Postal message. If I understood the code correctly the swiftToPostal
method of the PostalTransportClass
simply does not set any custom headers.
This does not only break the email logging feature, but also does not allow the application to pass any additional headers, which could break some workflows.
You're right, the headers don't get passed to Postal, they are just the only way I could think of for getting those two pieces of information into the transport class for creating log entries in our applications.
Our use of Postal has only been as a sending platform, we don't really log into it to analyse the messages going out for example. We tend to make extensive use of logging within our individual applications so its a better fit for us there.
Do you add additional custom headers to your MailMessage
or would it just be worthwhile for you to see the notifiable
information within Postal?
Ah, I actually thought that sending the custom headers is required for matching the webhook response to the actual model, but it seems that these header fields were not intended for that purpose. Still it would be nice to send custom headers I think.
Again, two solutions:
The official transport classes for Mailgun and SES send the raw message instead using a JSON format.
You could use the send/raw
endpoint of postal and pass the whole message as base64 String. This should include the headers source.
The other solution would be something along the lines of
<?php
private function swiftToPostal(Swift_Mime_SimpleMessage $swiftmessage) : SendMessage
{
if ($message->getHeaders()) {
$headers = $message->getHeaders()->getAll();
foreach( $headers as $header) {
if( $header instanceof Swift_Mime_Headers_UnstructuredHeader ) {
$postalmessage->header($header->getFieldName(), $header->getValue());
}
}
}
// ...
}
The best solution here is to switch to using the send/raw
endpoint, as the conversion from a Swift_Mime_SimpleMessage
to a SendMessage
causes a lot of the properties set by the builder to be lost (for example headers). Unless we supported every use case, which is difficult by the nature of the send/message
endpoint, moving to send/raw
is a better choice.
Unfortunately this would prevent us from being able to implement #9 as that endpoint does not accept the tag
property. Possibly @willpower232 could make a PR at atech/postal to allow that endpoint to accept tags.
I've stumbled across this post while searching for a solution why my List-Unsubscribe
header will not be passed to Postal. Are there any updates on this issue? It seems that the code hasn't be updated since with any kind of header handler etc.
I believe that the code is more flexible than it was when this issue was first created so it is possible there may be a solution but as my esteemed colleague noted, the best solution is to use the raw endpoint directly rather than trying to parse the headers and decide which ones are actually custom.
You could use an SMTP connection to Postal to achieve this as well.
Alright, thanks!
When using an SMTP connection, can i still use the webhook ability from your library? I guess so, right?
you could but you might struggle to identify which message the webhook relates to as using SMTP means you probably don't know the ID of the message