Skip to content
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

Headers are not passed to Postal Message #8

Open
a47ae opened this issue Jul 13, 2019 · 7 comments
Open

Headers are not passed to Postal Message #8

a47ae opened this issue Jul 13, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@a47ae
Copy link

a47ae commented Jul 13, 2019

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.

@willpower232
Copy link
Member

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?

@a47ae
Copy link
Author

a47ae commented Jul 15, 2019

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());
            }
        }
    }

    // ...
}

@Josh-G Josh-G added the enhancement New feature or request label Jul 16, 2019
@Josh-G
Copy link
Contributor

Josh-G commented Jul 17, 2019

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.

@Josh-G Josh-G self-assigned this Jul 23, 2019
@Pacerino
Copy link

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.

@willpower232
Copy link
Member

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.

@Pacerino
Copy link

Alright, thanks!

When using an SMTP connection, can i still use the webhook ability from your library? I guess so, right?

@willpower232
Copy link
Member

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

@Josh-G Josh-G removed their assignment Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants