Hi,
I am working on a ASP.NET Core WebAPI where I am using SendGrid to send emails. Earlier, I was able to use the helper class CreateSingleEmail to send a single mail to a single recipient.
Now, I wish to send the same email to multiple recipient in BCC so, the recipients are not able to see the other recipients.
I have gone through many documentation on this issue and even the previous similar issues raised for this but I am still unable to send the mails.
I have tried to use Personalization block too. I do not get any error per se but emails are not being sent through this.
Here is my method-
var apiKey = "MySendgridApiKey"
var client = new
SendGridClient(apiKey);
var msg = new SendGridMessage();
msg.SetFrom(new EmailAddress(fromEmail));
msg.AddTo(new EmailAddress(fromEmail), 1);
msg.SetBypassListManagement(true);
msg.SetBccSetting(true, fromEmail);
msg.AddSubstitution("%name1%", "Example User1");
msg.SetSubject(subject);
var personalization = new Personalization()
{
Bccs = toEmail
};
msg.AddBccs(toEmail);
msg.AddBccs(toEmail, 0, personalization);
msg.Serialize();
var response = client.SendEmailAsync(msg);
return true;
@thinkingserious , could you please look into this?
Thanks in advance!
@DrMeloMoney
@Muskan-14 if the requirement is to send a single email to multiple recipients (with the condition that the the users can't see other recipients) then you can use the overloaded CreateSingleEmailToMultipleRecipients method from the MailHelper class. It has a parameter named showAllRecipients which controls whether the recipients will be able to see each other. But in this case the recipients will be in the To section.
https://github.com/sendgrid/sendgrid-csharp/blob/master/src/SendGrid/Helpers/Mail/MailHelper.cs#L269
@Niladri24dutta, I had tried the same using this helper class but the recipients could still see the others in the mail.
I did not know about the showAllRecipients parameter. I will explore that and get back to you on this.
Thank you for bringing this to my notice.
Thanks for helping out @Niladri24dutta!
@Niladri24dutta , Your suggestion to use the helper class was very useful. Thank you for your help.
Furthermore, @thinkingserious @Niladri24dutta
Is it possible to send a different message in the body in some manner? With my mail, I would simply like to personalize the mail for the respective users by their username in the mail and would prefer that one recipient should not be able to view the other recipients.
Can we set different body content through personalization without use of pre defined template id in send grid portal?
I am not able to any property to set body content.
Most helpful comment
@Muskan-14 if the requirement is to send a single email to multiple recipients (with the condition that the the users can't see other recipients) then you can use the overloaded
CreateSingleEmailToMultipleRecipientsmethod from the MailHelper class. It has a parameter namedshowAllRecipientswhich controls whether the recipients will be able to see each other. But in this case the recipients will be in theTosection.https://github.com/sendgrid/sendgrid-csharp/blob/master/src/SendGrid/Helpers/Mail/MailHelper.cs#L269