Problem/Motivation

Though the Mandrill API does appear to support the addition of CC and BCC recipients, this functionality is not incorporated into the Mandrill module.

See the following excerpt from the Mandrill API documentation:
the header type to use for the recipient, defaults to "to" if not provided
From: https://mandrillapp.com/api/docs/messages.html

Proposed resolution

In MandrillMail.php, the following lines could be updated to incorporate CC and BCC recipients from mail headers:

    // Extract an array of recipients.
    $to = $this->mandrill->getReceivers($message['to']);

And the following function from MandrillService.php could be updated to apply the 'type' setting as needed to classify emails as either 'to', 'cc', or 'bcc'.

  /**
   * Helper to generate an array of recipients.
   *
   * @param mixed $receiver
   *   a comma delimited list of email addresses in 1 of 2 forms:
   *   user@domain.com
   *   any number of names <user@domain.com>
   *
   * @return array
   *   array of email addresses
   */
  public function getReceivers($receiver) {
    $recipients = array();
    $receiver_array = explode(',', $receiver);
    foreach ($receiver_array as $email) {
      if (preg_match(MANDRILL_EMAIL_REGEX, $email, $matches)) {
        $recipients[] = array(
          'email' => $matches[2],
          'name' => $matches[1],
        );
      }
      else {
        $recipients[] = array('email' => $email);
      }
    }
    return $recipients;
  }

Remaining tasks

Write the code and upload a patch for review and testing.

User interface changes

None.

API changes

None. Just that it would add support for CC and BCC addresses which Mandrill already has.

Data model changes

The $receiver variable in getReceivers would be either an string or an array. Which would have to be accounted for in the update. The update should provide a check of some kind to provide backward compatibility for string inputs.

Comments

merauluka created an issue. See original summary.

merauluka’s picture

Status: Active » Needs review
StatusFileSize
new4.32 KB

Attaching patch and marking ticket as "Needs review" to kick off testing.

merauluka’s picture

StatusFileSize
new4.32 KB

Updating patch to fix typo in comments.

merauluka’s picture

StatusFileSize
new803 bytes
new1.11 KB

Attaching an updated patch for when an email address doesn't have a name associated with it.

merauluka’s picture

StatusFileSize
new803 bytes
new3.93 KB

Man. I'm batting a thousand today. That last patch was only for a single commit. Fixing with complete patch.

Sheesh.

diogoviannaaraujo’s picture

This is really important for Drupal Commerce websites.
Most of admin confirmation comes as a CC

Hope this gets merged soon

criz’s picture

Status: Needs review » Reviewed & tested by the community

This patch works for us!

diogoviannaaraujo’s picture

Worked for me too

merauluka’s picture

Bumping this issue since it's now listed as RTBC.

samuel.mortenson’s picture

Assigned: Unassigned » rjacobsen0
knyshuk.vova’s picture

The patch looks good and applies successfully. +1 for RTBC.

The last submitted patch, 4: d8_add_support_for_cc_and_bcc-2881577-4.patch, failed testing. View results

rjacobsen0’s picture

Patch looks great. Thanks. Committing.

rjacobsen0’s picture

Status: Reviewed & tested by the community » Fixed

  • rjacobsen0 committed 934a3d1 on 8.x-1.x authored by merauluka
    Issue #2881577 by merauluka, diogoviannaaraujo, criz, samuel.mortenson,...

Status: Fixed » Closed (fixed)

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