Skip to content

Conversation

@t-richard
Copy link
Contributor

Q A
Branch? master
Bug fix? yes
New feature? no
Deprecations? no
Tickets none
License MIT
Doc PR none

Using this bridge I got an error from Mailjet API given below and this PR fixes this issue.

Error from Mailjet ```json { "Messages": [ { "Status": "error", "Errors": [ { "ErrorIdentifier": "xxxx", "ErrorCode": "send-0011", "StatusCode": 400, "ErrorMessage": "Header cannot be customized using the \"Headers\" collection. Please use the dedicated property to set this header.", "ErrorRelatedTo": [ "Headers[\"Reply-To\"]" ] } ] } ] } ```

As detailed in the Mailjet API doc, ReplyTo is a single email address whereas the Symfony\Mime\Email class allows for several emails in ReplyTo.

I implemented the same logic as the Sendgrid bridge but added logging (I first thought about throwing an exception but this would reduce transport interchangeability).

Note : Reply-To is not listed in the "Forbidden headers" section of Mailjet's documentation but the API response is clear about the expected input.

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.

Makes sense, but I would prefer an exception instead of the logged warning. 👍🏻

}
if ($emails = $email->getReplyTo()) {
if (1 < $length = \count($emails)) {
$this->getLogger()->warning(sprintf('Mailjet\'s API only supports one Reply-To email, %d given. The first one will be used.', $length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would throw an exception instead. I think that having more than one Reply-To address is an edge case and if it happens, it's important to make sure that the dev understands that it is not supported. I understand the interoperability argument, but I think it's better here to fail when something is not supported.

Can you also make the same change in Sendgrid to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot wouldn't adding this change to Sengrid break backward-compatibility as some apps may rely on the current behaviour of the transport ?

Also, if transports are not fully interoperable, should we document it and maybe list transport specificities ?

@t-richard
Copy link
Contributor Author

Changed from a logged warning to an exception and adapted tests.

@fabpot
Copy link
Member

fabpot commented Sep 15, 2020

Thank you @t-richard.

@fabpot fabpot closed this Sep 15, 2020
@fabpot fabpot force-pushed the mailer-mailjet-reply-to branch from c8ed052 to 1ff3e29 Compare September 15, 2020 05:09
fabpot added a commit that referenced this pull request Sep 15, 2020
…t-richard)

This PR was squashed before being merged into the 5.2-dev branch.

Discussion
----------

[Mailer] Mailjet - Allow using Reply-To with Mailjet API

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

Using this bridge I got an error from Mailjet API given below and this PR fixes this issue.
<details>
<summary>Error from Mailjet</summary>
```json
{
    "Messages": [
        {
            "Status": "error",
            "Errors": [
                {
                    "ErrorIdentifier": "xxxx",
                    "ErrorCode": "send-0011",
                    "StatusCode": 400,
                    "ErrorMessage": "Header cannot be customized using the \"Headers\" collection. Please use the dedicated property to set this header.",
                    "ErrorRelatedTo": [
                        "Headers[\"Reply-To\"]"
                    ]
                }
            ]
        }
    ]
}
```
</details>

As detailed in [the Mailjet API doc](https://dev.mailjet.com/email/reference/send-emails/index.html#v3_1_post_send), `ReplyTo` is a single email address whereas the `Symfony\Mime\Email` class allows for several emails in `ReplyTo`.

I implemented the [same logic as the Sendgrid bridge](https://github.com/symfony/symfony/blob/0f5ac5dc8f944a719e7d71729c0a63e1cfc9c6b5/src/Symfony/Component/Mailer/Bridge/Sendgrid/Transport/SendgridApiTransport.php#L96) but added logging (I first thought about throwing an exception but this would reduce transport interchangeability).

Note : `Reply-To` is not listed in the ["Forbidden headers" section of Mailjet's documentation](https://dev.mailjet.com/email/guides/send-api-v31/#add-email-headers) but the API response is clear about the expected input.

Commits
-------

1ff3e29 [Mailer] Mailjet - Allow using Reply-To with Mailjet API
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 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.

5 participants