Skip to content

[Mailer][Mailgun] Support more headers #35776

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
Nyholm opened this issue Feb 18, 2020 · 12 comments · Fixed by #36148
Closed

[Mailer][Mailgun] Support more headers #35776

Nyholm opened this issue Feb 18, 2020 · 12 comments · Fixed by #36148

Comments

@Nyholm
Copy link
Member

Nyholm commented Feb 18, 2020

Mailgun has a number of headers available. Example is o:deliverytime and v:my-var. There is no way of setting these headers with the current implementation. All headers get prefixed with h:. See MailgunApiTransport::getPayload()

It would be a good idea to allow user to set these headers. See here for a complete list: https://documentation.mailgun.com/en/latest/api-sending.html#sending

I suggest to only allow headers that begins with h:, t:, o:, v: and then fallback to prefix with h:. That will allow us to add this in a BC compatible way.

@fabpot
Copy link
Member

fabpot commented Feb 18, 2020

That works for me.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 18, 2020

Hm.
How?

I’m doing something like this:

$email->getHeaders()->addTextHeader('o:deliverytime', $sendAt->format(\DateTimeInterface::RFC2822));

But I get a payload like: “h:o:deliverytime

@greedyivan
Copy link
Contributor

greedyivan commented Feb 21, 2020

MailgunApiTransport does not do much with various headers:

foreach ($headers->all() as $name => $header) {
if (\in_array($name, $headersToBypass, true)) {
continue;
}
if ($header instanceof TagHeader) {
$payload['o:tag'] = $header->getValue();
continue;
}
if ($header instanceof MetadataHeader) {
$payload['v:'.$header->getKey()] = $header->getValue();
continue;
}
$payload['h:'.$name] = $header->getBodyAsString();
}

o:tag with

$email->getHeaders()->add(new TagHeader('tag'));

v:my-var with

$email->getHeaders()->add(new MetadataHeader('my-var', 'value'));

h:X-My-Header with

$email->getHeaders()->addTextHeader('oX-My-Header', 'value');

@Nyholm
Copy link
Member Author

Nyholm commented Feb 21, 2020

Oh. I see. Thank you. I was just looking at 5.0.

But there is still no way to set o:deliverytime

@greedyivan
Copy link
Contributor

It was added here: #35047

That was done for Postmark. To fully support Mailgun, it should be done something similar.

@greedyivan
Copy link
Contributor

Regarding these:

@fabpot, can we implement a CustomHeader class instead of a bunch of specialized classes as TagHeader, MetadataHeader and so on, to move all customization logic to the ApiTransport layer?

@Nyholm
Copy link
Member Author

Nyholm commented Feb 22, 2020

@greedyivan Yes, I think that is a good idea. The CustomHeader should be able to define both its name and value. Drawbacks of using the custom header is of course that values will be provider specific.

Do you mind submitting a PR?

@greedyivan
Copy link
Contributor

@Nyholm Drawbacks of using the custom header is of course that values will be provider specific.

I did some research and found out that the only place where it is needed is MailgunApiTransport. Even MailgunHttpTransport, as well as transports of all other providers, do not change the name of the header.

Thus, I suggest break BC and removing the addition of h: to the header in MailgunApiTransport by default.

The upgrade will consist of the need to explicitly set the full name of the header.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 22, 2020

Thank you!

Im all for making things consistent. But I really don't want to break BC.
Since this feature is MailgunApiTransport specific again, could we change it slightly so we allow all headers that begins with h:, t:, o:, v: and then fallback to prefix with h:. That will allow us to add this in a BC compatible way.

@greedyivan
Copy link
Contributor

It is much more complicated than just adding prefix support.

Currently, MailgunApiTransport does not support these parameters of Mailgun API:

  • amp-html
  • template
  • t:version
  • t:text
  • o:dkim
  • o:deliverytime
  • o:deliverytime-optimize-period
  • o:testmode
  • o:tracking
  • o:tracking-clicks
  • o:tracking-opens
  • o:require-tls
  • o:skip-verification
  • recipient-variables

Just add support for t: doesn't mean anything without template.

I understand that the Mailer component is not a full substitution for the original API library, but we must decide what part of that API it should support. It looks good that it supports arbitrary custom headers using the h: prefix. Should it supports any of Mailgun extensions? If not and we want not to break BC, I think it’s better not to add anything at all.

@OskarStark
Copy link
Contributor

Let’s not complicate it to much, it’s a BC break but it’s still experimental, so it should be no problem to change this behavior if it makes sense. We did this quite often in messenger component

@fabpot
Copy link
Member

fabpot commented Feb 25, 2020

What @OskarStark said. The goal of a component being experimental is precisely to allow us to break BC whenever it makes sense.

@fabpot fabpot closed this as completed Mar 23, 2020
fabpot added a commit that referenced this issue Mar 23, 2020
This PR was squashed before being merged into the 5.1-dev branch.

Discussion
----------

[Mailer][Mailgun] Support more headers

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | yes
| Tickets       | Fix #35776
| License       | MIT
| Doc PR        |

Im not sure if this should be classified as a bug since "setting headers are broken". Ie, you cannot use some Mailgun API features.

Or, this may be a feature because now you may specify any supported custom header you want.

Commits
-------

537c8b8 [Mailer][Mailgun] Support more headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants