BCC not working properly when batch sending
Method-Development opened this issue · 10 comments
Issue seen on mobile iOS.
If you do “addRecipient” it works properly but if you use “addBccRecipient” the first email goes to the correct person but subsequent emails go to whoever was BCC’d.
Hello @Method-Development Are you sure that you use in a correct way BCC ? Each BCC recipient will not know about another BCC. But They will see original recipient.
Here is example of code usage
try {
$builder = new MessageBuilder();
$builder->setFromAddress("xxxx@gmail.com");
$builder->addBccRecipient('x1@gmail.com');
$builder->addBccRecipient('x2@gmail.com');
$builder->addToRecipient('yyyyyy@gmail.com');
$builder->setSubject('Test BCC');
$builder->setTextBody("This is the text body of the message!");
$builder->setHtmlBody("<html><p>This is the HTML body of the message</p></html>");
$res = $mgClient->messages()->send($domain, $builder->getMessage());
print_r($res);
} catch (Exception $exception) {
echo sprintf('HTTP CODE - %s,', $exception->getCode());
echo sprintf('Error - %s', $exception->getMessage());
}@oleksandr-mykhailenko thanks for responding! This is using their bulk sending, the non-bulk works as intended.
On my phone(latest iOS using the built in mail app) I set up 3 email accounts, then used the bulk sending to email them. The first is always correct but the others show the first recipient's address and does not show the to/from/bcc properly.
This is an example of the code using their php package:
$mgClient = Mailgun::create(config('mailgunbatchsending.key'), config('mailgunbatchsending.hostname'));
$domain = config('mailgunbatchsending.domain');
$batchMessage = $mgClient->messages()->getBatchMessage($domain);
$batchMessage->setFromAddress('no-reply@mysite.com <no-reply@mysite.com>', array("site"=>'mysite'));
$batchMessage->setSubject($this->subject);
$batchMessage->setHtmlBody($this->rendered_html);
if(isset($this->users) && $this->users->count() > 0){
foreach($this->users as $user)
{
$batchMessage->addToRecipient($user->email, array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $user->email])));
}
}
else{
$batchMessage->addToRecipient($this->to, array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $this->to])));
}
if(isset($this->bcc)){
$batchMessage->addBccRecipient($this->bcc, array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $this->bcc])));
}
$batchMessage->finalize();
@oleksandr-mykhailenko thanks for responding! This is using their bulk sending, the non-bulk works as intended.
On my phone(latest iOS using the built in mail app) I set up 3 email accounts, then used the bulk sending to email them. The first is always correct but the others show the first recipient's address and does not show the to/from/bcc properly.
This is an example of the code using their php package:
$mgClient = Mailgun::create(config('mailgunbatchsending.key'), config('mailgunbatchsending.hostname')); $domain = config('mailgunbatchsending.domain'); $batchMessage = $mgClient->messages()->getBatchMessage($domain); $batchMessage->setFromAddress('no-reply@mysite.com <no-reply@mysite.com>', array("site"=>'mysite')); $batchMessage->setSubject($this->subject); $batchMessage->setHtmlBody($this->rendered_html); if(isset($this->users) && $this->users->count() > 0){ foreach($this->users as $user) { $batchMessage->addToRecipient($user->email, array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $user->email]))); } } else{ $batchMessage->addToRecipient($this->to, array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $this->to]))); } if(isset($this->bcc)){ $batchMessage->addBccRecipient($this->bcc, array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $this->bcc]))); } $batchMessage->finalize();
Oh, I see now. SO let me test this. And I will back to you with answer. I can't promise to answer you today, But for tomorrow I will be ready.
Thank you for providing example, it's much better now to understand the flow of the code
Hello @Method-Development
So I tested a few scenarios. Looks like it was designed to work in the next way.
If you use only addToRecipient - each recipient will not know about another. Just separated email to each recipient.
If you user addCcRecipient - email app will show you the addresses of the copy of this email
if you use - addBccRecipient - it's a hidden copy and nobody will know about them. It's regular behavior.
$batchMessage = $mgClient->messages()->getBatchMessage($domain);
$batchMessage->setFromAddress('mihaskep@gmail.com');
$batchMessage->setSubject('BATCH TEST');
$batchMessage->setHtmlBody("<html><p>This is the HTML body of the message</p></html>");
$batchMessage->addToRecipient('xxx@gmail.com');
$batchMessage->addCcRecipient('yyy@gmail.com');
$batchMessage->addBccRecipient('zzz@gmail.com');
$batchMessage->finalize();
Additional info
What does CC mean in email?
By putting the email address(es) in the Cc field you send a copy of the email to those recipient(s) for their information only, indicating that no reply is required or expected. Those email addresses are also visible to the main recipient (whose address is in the “To” field) and they can decide whether to reply to the sender only (by choosing “Reply”) or to also include the cc’ed addresses (by clicking “Reply all”).
What does BCC mean in email?
The recipients you add in the Bcc field are invisible to all other recipients (under To or Cc). This option is useful if you prefer to keep the email addresses private. It also means that the bcc'ed recipients will not receive any reply emails from the other recipients, even if they select “Reply all”. In other words, the difference between cc and bcc is that both are used for sending emails to additional recipients, but only you as the sender can see all the names listed under Bcc.
@oleksandr-mykhailenko yeah I'm using the BCC it works as intended with one to email but if you use recipient variables and multiple to addresses it does not work as intended.
So if you do this:
$batchMessage->addToRecipient("email1@gmail.com", array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $user->email])));
$batchMessage->addToRecipient("email2@gmail.com", array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $user->email])));
$batchMessage->addToRecipient("email3@gmail.com", array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $user->email])));
$batchMessage->addBccRecipient("hiddenaddress@gmail.com", array('site'=>'mysite', 'unsubscribe_from_email_link' => URL::signedRoute('disableEmailNotifications', ['token' => $this->bcc])));
And you'll notice 2 of the 3 will have an incorrect setup when they receive the email(wrong to)