Problem/Motivation
When using the Brevo Mailer submodule to send all site emails through Brevo, it cannot send emails if multiple email addresses are in the "to" field. I received the same errors whether using the Send Test email form, the test email form from the Reroute email module, and webform handlers when emailing multiple people.
Steps to reproduce
- Install module
- Enable and configure Brevo mailer submodule
- Set up site to send all emails through Brevo mailer (I used Mail System to do this)
- Navigate to Configuration > Web Services > Brevo > Brevo Mailer
- Click on "Send test email" tab
- Enter 2 email address in the "To" field, separated with a comma
- Click on 'Send' button
- Receive error message that sending failed
- There should be also be an error log item of "Exception occurred while trying to send test email" which contains the message "Client error: `POST https://api.brevo.com/v3/smtp/email` resulted in a `400 Bad Request` response: {"code":"invalid_parameter","message":"email is not valid in to"}"
Proposed resolution
Check for multiple email address by checking for commas and break into an array in the BrevoMail::buildMessage method.
According to Brevo Documentation, multiple To addresses must be an array of arrays
From their documentation:
List of email addresses and names (optional) of the recipients. For example,
[{"name":"Jimmy", "email":"jimmy98@example.com"}, {"name":"Joe", "email":"joe@example.com"}]
https://developers.brevo.com/reference/sendtransacemail
Remaining tasks
I have working patch that I will create an MR for.
User interface changes
None
API changes
None, solution will check if $message['to'] is already an array (in case users fixed this on their own), and if not it will format it how Brevo needs it.
Data model changes
None
Issue fork brevo-3546064
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
averagejoe3000Comment #5
averagejoe3000Comment #6
averagejoe3000Comment #7
renrhafThanks, the fix is included in the main branch with multiple changes on CI/CD & testing.
Comment #11
averagejoe3000This is great, thank you. Would mind updating the contribution record and giving credit to me for this issue?
Comment #12
renrhafSorry, of course, I've added the wrong username in the commit message so updated contribution on drupal.org manually, it should be good now. Have a nice day !