Skip to content

[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

Closed

Conversation

AndreiIgna
Copy link

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets no
License MIT

Postmark has some helpful functionality to tag emails, to make is easier to sort or filter in their UI.
Screenshot 2019-11-30 at 17 17 50

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:

// creates $email
$email->getHeaders()->addTextHeader('Tag', 'account-emails');

Cheers

@AndreiIgna AndreiIgna changed the title Updated - Send email tag to Postmark API [Mailer] Send email tag to Postmark API Dec 2, 2019
Copy link
Contributor

@OskarStark OskarStark left a 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?

@AndreiIgna
Copy link
Author

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

@fabpot fabpot added Feature and removed Bug labels Dec 3, 2019
@fabpot fabpot added this to the next milestone Dec 3, 2019
@fabpot fabpot added the Mailer label Dec 3, 2019
@kbond
Copy link
Member

kbond commented Dec 12, 2019

@AndreiIgna what about metadata?

@AndreiIgna
Copy link
Author

@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.

@AndreiIgna
Copy link
Author

@kbond adding the metadata seems a bit more complicated than the Tag, because it should support multiple values.
Saying this only because the way to add the metadata to an email needs to be decided before implementation, and maybe this can be started as a different issue/PR

@kbond
Copy link
Member

kbond commented Dec 19, 2019

@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.

@fabpot
Copy link
Member

fabpot commented Jan 10, 2020

Closing in favor of #35050 or similar. Adding tag being quite common among providers, I prefer a generic solution.

@fabpot fabpot closed this Jan 10, 2020
fabpot added a commit that referenced this pull request Jan 30, 2020
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
@AndreiIgna AndreiIgna deleted the mailer-fix-postmark-tagging branch March 6, 2020 15:24
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.1 May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants