-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Mailer] Send email tag to Postmark API #34766
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a testcase?
I checked how to add a test for this, but I noticed tests for Transports are only for Transport connection https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Mailer/Bridge/Postmark/Tests/Transport/PostmarkApiTransportTest.php and not JSON payloads. This change is for the JSON payload sent to Postmark API, and the modified field is set in the standard email headers. I'm not sure how and where to add it |
@AndreiIgna what about metadata? |
@fabpot saw you marked this as Feature, still ok to be based on 4.4? I've added a test for PostmarkApiTransport that covers the basic sending + adding tag. |
@kbond adding the metadata seems a bit more complicated than the Tag, because it should support multiple values. |
@AndreiIgna yeah, I see what you mean. Other transports like Mailgun support metadata as well. Seems like something that needs to be standardized. I'll open an issue about this. |
Closing in favor of #35050 or similar. Adding tag being quite common among providers, I prefer a generic solution. |
This PR was merged into the 5.1-dev branch. Discussion ---------- [Mailer] added tag/metadata support | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #35047 | License | MIT | Doc PR | todo This is an alternative to #34766 for adding tag and metadata support in a more generalized way. Most transports allow for open/click tracking headers - maybe this should be handled in a similar way? I added implementations for the Postmark (SMTP and API) and Mailgun (SMTP and API) transports. I can add others and tests/docs if this is acceptable. ### Example: ```php use Symfony\Component\Mailer\Header\MetadataHeader; use Symfony\Component\Mailer\Header\TagHeader; $email->getHeaders()->add(new TagHeader('password-reset')); $email->getHeaders()->add(new MetadataHeader('Color', 'blue')); $email->getHeaders()->add(new MetadataHeader('Client-ID', '12345')); ``` The Postmark/Mailgun providers will parse these into their own headers/payload. For transports that don't support tags/metadata, these are just added as custom headers: ``` X-Tag: password-reset X-Metadata-Color: blue X-Metadata-Client-ID: 12345 ``` Commits ------- f2cdafc [Mailer] added tag/metadata support
Postmark has some helpful functionality to tag emails, to make is easier to sort or filter in their UI.

At the moment, tags can't be added when using the API transport. If adding a header "Tag: email-tag" to current email, the JSON payload is generated with that tag in "Headers" line and doesn't work.
This PR would allow the "Tag" header to be added at the root of JSON payload, ensuring valid payload for Postmark API https://postmarkapp.com/developer/api/email-api making this work properly:
Cheers