mail icon indicating copy to clipboard operation
mail copied to clipboard

fix(transports/brevo): brevo allow only one replyTo address

Open MaximeMRF opened this issue 1 year ago • 6 comments

❓ Type of change

  • [x] 🐞 Bug fix (a non-breaking change that fixes an issue)
  • [ ] 👌 Enhancement (improving an existing functionality like performance)
  • [ ] ✨ New feature (a non-breaking change that adds functionality)
  • [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Brevo allow only one replyTo address as a object not a array object

Not valid:

curl -X POST "https://api.brevo.com/v3/smtp/email" \
-H "accept: application/json" \
-H "api-key: xkeysib-dunno" \
-H "Content-Type: application/json" \
-d '{
  "sender": {
    "name": "Sender Name",
    "email": "[email protected]"
  },
  "to": [
    {
      "email": "[email protected]",
      "name": "Recipient Name"
    }
  ],
  "replyTo": [{
    "email": "[email protected]",
    "name": "Reply To Name"
  }],
  "subject": "Your Subject Here",
  "htmlContent": "<html><body><p>Your email content here.</p></body></html>"
}'

Error: {"code":"invalid_parameter","message":"replyTo is not valid"}

If you don't pass a array but an object directly it works perfectly

curl -X POST "https://api.brevo.com/v3/smtp/email" \
-H "accept: application/json" \
-H "api-key: xkeysib-dunno" \
-H "Content-Type: application/json" \
-d '{
  "sender": {
    "name": "Sender Name",
    "email": "[email protected]"
  },
  "to": [
    {
      "email": "[email protected]",
      "name": "Recipient Name"
    }
  ],
  "replyTo": {
    "email": "[email protected]",
    "name": "Reply To Name"
  },
  "subject": "Your Subject Here",
  "htmlContent": "<html><body><p>Your email content here.</p></body></html>"
}'

MaximeMRF avatar Oct 11 '24 13:10 MaximeMRF

Thanks for the fix. Can you please share some link to the documentation that has an example of replyTo? It will be helpful for reference in the future

thetutlage avatar Oct 14 '24 05:10 thetutlage

Hi @thetutlage,

Here is a example on the documentation

MaximeMRF avatar Oct 14 '24 07:10 MaximeMRF

I'm not entirely convinced about the proposed fix.

Rather than just taking the first item from the array, we should either prevent passing an array to this driver, or ensure it's an array with a single item and directly call #formatAddress.

What do you think?

RomainLanz avatar Oct 14 '24 07:10 RomainLanz

I think the internals of the Mail package shouldn't format data as per the requirements of a driver as they might be different across the drivers.

So, drivers receives a fixed shape and they can change the data for the underlying API call.

thetutlage avatar Oct 14 '24 08:10 thetutlage

So, drivers receives a fixed shape and they can change the data for the underlying API call.

But it also means I can write an array there, and it will only take the first item out of nowhere. It should be adequately documented.

Nevertheless, we can use this.#formatAddress(mail.data.replyTo[0]) instead.

RomainLanz avatar Oct 14 '24 08:10 RomainLanz

Yeah, the nuances of the drivers have to be documented

thetutlage avatar Oct 14 '24 09:10 thetutlage

An update on why this has never been merged ?

arthur-pigeon avatar Mar 19 '25 15:03 arthur-pigeon

Closed in favor of #106 . I will update the docs to mention this

thetutlage avatar Mar 20 '25 03:03 thetutlage