This module currently only supports "to" recipients when sending mail. If you specify CC or BCC, it does nothing with those. If you want to use those, you have to implement hook_mandrill_mail_alter in order to add any CC or BCC recipients defined in your message headers. I have done that in my particular use case, but it does not seem like that should be necessary. CC and BCC just works automatically when using standard Drupal mail, so it stands to reason that other mail systems should also implement them, as well as any other custom mail headers you define, automatically - at least as best as the mail system can support.

It would be easy enough in the Mandrill module to look for $message['headers']['Cc'] and $message['headers']['Bcc'] values and if present add them to the "to" array for Mandrill with the appropriate "type" parameter.

Comments

teknocat’s picture

Here is a possible patch (un-tested).

teknocat’s picture

Oops, that last patch was missing the most important thing - specifying what "type" each recipient email address is. Here's an updated one.

thechanceg’s picture

I have tested #2 and it is working well. The code looks good, I suggest commiting this patch as I'm sure others would expect these headers to work out of the box.
Thank you teknocat.

kalabro’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.89 KB

Re-applyed. Works well.

juanjo4’s picture

I've tested #2 and it seems to work fine, I sent emails with bcc recipients but the email is delivered to the user as a "to" recipient, I'm not sure if this is an expected behavior or if this happen due to mandrill settings.

So, I've reverted the patch because I obtained the same functionality adding all my recipients in the 'to' field.

Thanks anyway.

thechanceg’s picture

Hey @juanjo4,

On Mandrills settings page they give you the option "Expose The List Of Recipients When Sending To Multiple Addresses". It is unchecked by default. With this setting turned off, users will not see the other people the email was sent to.

sinn’s picture

Status: Needs review » Reviewed & tested by the community

#4 works good

m1n0’s picture

Hmm making BCC into "to" doesn't seem to be what we need, mandrill does support BCC, see https://mandrillapp.com/api/docs/messages.html, and it requires key bcc_address.

There even is code for it in the module, from mandrill.mail.inc:
'bcc_address' => isset($message['bcc_email']) ? $message['bcc_email'] : NULL, (line 164),
but that does not seem to be doing anything at all, as 'bcc_email' is never used elsewhere in the module, so never populated.

Changing that one line to look for the actual Bcc header from message, as normally used by Drupal seems to do the trick, it works for me when sending emails via code. See attached patch.

m1n0’s picture

Status: Reviewed & tested by the community » Needs review
thechanceg’s picture

Status: Needs review » Reviewed & tested by the community

@m1n0 is mistaken. If you follow the link he provides the documentation clearly states this for the "to" key:
type (string) the header type to use for the recipient, defaults to "to" if not provided oneof(to, cc, bcc)
The "to" array is the proper place to add CC & BCC addresses.

m1n0’s picture

@thechanceg is right, I didnt read the docs properly - at first I thought that the provided patch in #4 sends CCs and BCCs as any other TO. On the other hand, "bcc_address" works as well and is supported by the documentation, so my patch in #8 works as well, at least for single address. Seems like bit of a redundancy, but #4 is the correct approach.

sinn’s picture

#4 have problems when system can't connect to mandrill in code:

watchdog('mandrill', 'Error sending email from %from to %to. Function %function not found.',
        array(
          '%from' => $message['from_email'],
          '%to' => $message['to'],
          '%function' => $function,
        ),
        WATCHDOG_ERROR
      );

$message['to'] isn't an array

mrchristophy’s picture

#4 worked for me, except that the received e-mails only showed the CC email address, not the 'to'. Removing the 'Cc' item in the headers seems to fix it. I did this with unset($headers['Cc']);

spleshka’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.79 KB

Patch in #4 has several issues (though it works):
1. When bcc is used then the primary recipient of email gets replaced by bcc recipient (which is not ideal)
2. Issue mentioned in #12
3. Issue mentioned in #13

So I've fixed all those issues and submitting the resulting patch. Note that it also has improvements to the comments & code style.

oadaeh’s picture

There is a problem with the patch in #14. The re-factoring of the mandrill_get_to() function now takes as it's parameter an array:

+ * @param $message array
+ *   An array containing the email data.

However, the initial call to it passes in a string:

     // Extract an array of recipients.
     $to = mandrill_get_to($message['to']);

Rather than re-work everything, I simply included a bit from the patches in #2 and #4:

     // Extract an array of recipients.
-    $to = mandrill_get_to($message['to']);
+    $to = mandrill_get_to($message);

And now the email addresses in the To field get processed correctly.

roam2345’s picture

patch from #15 applied and Bcc mails through mandrill are sending for us.

samuel.mortenson’s picture

Assigned: Unassigned » rjacobsen0
rjacobsen0’s picture

Status: Needs review » Reviewed & tested by the community

Code works well. Will commit.

  • rjacobsen0 committed f209ce1 on 7.x-2.x authored by oadaeh
    Issue #2316731 by teknocat, oadaeh, m1n0, kalabro, Spleshka, thechanceg...
rjacobsen0’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, all, for the good work!

Status: Fixed » Closed (fixed)

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