sendgrid-csharp icon indicating copy to clipboard operation
sendgrid-csharp copied to clipboard

Unable to send multiple emails in BCCs using Sendgrid API for C#

Open Muskan-14 opened this issue 8 years ago • 8 comments

Issue Summary

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;

Technical details:

  • Platform ( ASP.NET Core WebAPI)
  • .NET Core Version: 2.0.8

Muskan-14 avatar Sep 25 '18 18:09 Muskan-14

@thinkingserious , could you please look into this? Thanks in advance!

Muskan-14 avatar Sep 25 '18 18:09 Muskan-14

@DrMeloMoney

Muskan-14 avatar Sep 26 '18 00:09 Muskan-14

@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 avatar Sep 28 '18 19:09 Niladri24dutta

@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.

Muskan-14 avatar Sep 28 '18 20:09 Muskan-14

Thanks for helping out @Niladri24dutta!

thinkingserious avatar Oct 02 '18 20:10 thinkingserious

@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.

Muskan-14 avatar Oct 03 '18 06:10 Muskan-14

Hi @Muskan-14,

Perhaps our transactional templates is what you need.

With Best Regards,

Elmer

thinkingserious avatar Oct 04 '18 21:10 thinkingserious

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.

husainagha-gep avatar Dec 14 '20 18:12 husainagha-gep