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

  1. Install module
  2. Enable and configure Brevo mailer submodule
  3. Set up site to send all emails through Brevo mailer (I used Mail System to do this)
  4. Navigate to Configuration > Web Services > Brevo > Brevo Mailer
  5. Click on "Send test email" tab
  6. Enter 2 email address in the "To" field, separated with a comma
  7. Click on 'Send' button
  8. Receive error message that sending failed
  9. 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

Command icon 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

averagejoe3000 created an issue. See original summary.

averagejoe3000 changed the visibility of the branch 1.0.x to hidden.

averagejoe3000’s picture

Issue summary: View changes
averagejoe3000’s picture

Status: Active » Needs review
averagejoe3000’s picture

Title: Cannot send to multiple email address using Brevo Mailer » Cannot send to multiple email addresses using Brevo Mailer
renrhaf’s picture

Status: Needs review » Fixed

Thanks, the fix is included in the main branch with multiple changes on CI/CD & testing.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

averagejoe3000’s picture

This is great, thank you. Would mind updating the contribution record and giving credit to me for this issue?

renrhaf’s picture

Sorry, 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 !