Updated Aug 29, 2024
- Use of of the offical SDKs to add Bccs easily
When sending emails in using Sendgrid, you may want to Bcc a specific email address. This is super simple to do by using the Sendgrid SDK or the Laravel mailer package.
Contents
Bcc with Sendgrid PHP SDK
If you are using the official PHP library you can add a single Bcc
$email->addBcc("[email protected]", "Test User");
or if you want to add multiple Bccs the following snippet where $bccEmails is an array of emails.
$bccEmails = [
"[email protected]" => "Example User2",
"[email protected]" => "Example User3"
];
$email->addBccs($bccEmails);
The full snippet can be viewed in their offical Github docs:
Bcc with Sendgrid in Laravel
If you are using Laravel, it's just as straightforward by adding the ->bcc() snippet to your Mail function call:
Mail::to($request->user())
->cc($moreUsers)
->bcc($evenMoreUsers)
->send(new OrderShipped($order));
The full snippet can be viewed in the offical Laravel docs:
Bcc with Sendgrid Python SDK
Here's how you would do it with the python SDK
message.bcc = Bcc('[email protected]', 'Example User7', p=0)
message.bcc = [
Bcc('[email protected]', 'Example User8', p=0),
Bcc('[email protected]', 'Example User9', p=0)
]
The full snippet can be viewed in their offical Github docs
Conclusion
As you can see it's extremely simple to add a Bcc to Sendgrid emails. If you have another method, comment below and we will add it to the post.
Theo 08.22.2024
well that was easier than I thought. The sendgrid docs miss simple stuff like this.