fix(transports/brevo): brevo allow only one replyTo address
❓ 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>"
}'
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
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?
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.
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.
Yeah, the nuances of the drivers have to be documented
An update on why this has never been merged ?
Closed in favor of #106 . I will update the docs to mention this