Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't send BCC emails through Mandrill (via Laravel)

I am unable to send emails to users through the Mandrill plugin in Laravel using BCC. I can send emails "to" the addresses, as follows:

Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
  foreach ($emails as $email) {
    $message->to($email);
  }

  $message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});

This works just fine. However, if I try to BCC the same users:

Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {
  foreach ($emails as $email) {
    $message->bcc($email);
  }

  $message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');
});

Nothing happens. Mandrill doesn't even acknowledge that the request came in. Any ideas why this isn't working? If it helps, here are my raw email headers:

Message-ID: <[email protected]>
Date: Thu, 07 Aug 2014 11:15:35 -0400
Subject: Coach McTest would like to be your Coach on Nudge!
From: Nudge Info <[email protected]>
Bcc: Chris Garson <[email protected]>
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
like image 638
Chris Garson Avatar asked Aug 07 '14 15:08

Chris Garson


2 Answers

I can confirm that sending emails to Bcc users doesn't really work as expected in Mandrill.

The easiest way to send what you want (single email to multiple addresses, with each addressee only seeing their own name in the delivery list), is to set the X-MC-PreserveRecipients header to false and then just send the email using the To field rather than Bcc.

This will send the email as if it were sent to each recipient individually, rather than as a group email - nobody will know who else was sent the email.

Here's how to do it in Laravel using your example:

Mail::send('emails.coach_invite', $data, function($message) use ($coach, $emails) {

    foreach ($emails as $email) {
        $message->to($email);
    }

    $message->subject($coach->first_name.' '.$coach->last_name.' has invited you to try Nudge!');

    $headers = $message->getHeaders();
    $headers->addTextHeader('X-MC-PreserveRecipients', 'false');
});

Note that I'm using $message->to() to address the email and then adding the X-MC-PreserveRecipients header which is set to false.

like image 193
Simon Hampel Avatar answered Sep 30 '22 06:09

Simon Hampel


I worked for me both CC and BCC way.

Ref document: https://mandrill.zendesk.com/hc/en-us/articles/205582117-Using-SMTP-Headers-to-customize-your-messages

Search keyword: X-MC-PreserveRecipients

    $headers = $message->getHeaders();
    $headers->addTextHeader('X-MC-PreserveRecipients', true);
like image 25
Mike Nguyen Avatar answered Sep 30 '22 04:09

Mike Nguyen