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
Comment #1
teknocat commentedHere is a possible patch (un-tested).
Comment #2
teknocat commentedOops, that last patch was missing the most important thing - specifying what "type" each recipient email address is. Here's an updated one.
Comment #3
thechanceg commentedI 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.
Comment #4
kalabroRe-applyed. Works well.
Comment #5
juanjo4 commentedI'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.
Comment #6
thechanceg commentedHey @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.
Comment #7
sinn commented#4 works good
Comment #8
m1n0 commentedHmm 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.
Comment #9
m1n0 commentedComment #10
thechanceg commented@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.
Comment #11
m1n0 commented@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.
Comment #12
sinn commented#4 have problems when system can't connect to mandrill in code:
$message['to'] isn't an array
Comment #13
mrchristophy commented#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']);
Comment #14
spleshkaPatch 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.
Comment #15
oadaeh commentedThere 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:
However, the initial call to it passes in a string:
Rather than re-work everything, I simply included a bit from the patches in #2 and #4:
And now the email addresses in the To field get processed correctly.
Comment #16
roam2345 commentedpatch from #15 applied and Bcc mails through mandrill are sending for us.
Comment #17
samuel.mortensonComment #18
rjacobsen0 commentedCode works well. Will commit.
Comment #20
rjacobsen0 commentedThanks, all, for the good work!