Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateSingleEmailToMultipleRecipients sends separate emails for to recipients #1054

Closed
D1mitry opened this issue Oct 8, 2020 · 1 comment
Labels
status: waiting for feedback waiting for feedback from the submitter type: getting started question while getting started type: question question directed at the library

Comments

@D1mitry
Copy link

D1mitry commented Oct 8, 2020

Hi Team,

I've seen some closed issues with a similar topics, but I assume, if they are closed, they should be resolved. We used send grid to send emails, with specified lists for tos and ccs, and we faced with the issue that CreateSingleEmailToMultipleRecipients sends separate email for each email address in the tos list, if showAllRecipients = false (last parameter default value), and just first recipient see himself and recipients in cc, second - just see himself. We just tried this for 2 recipients in tos and several in ccs. Unfortunately we haven't tried for more recipients on tos. When we set showAllRecipients = true single email to all recipients has been sent.
In my opinion helper method which called CreateSingleEmailToMultipleRecipients shouldn't send separate email, that is not an expected behavior. If I would have separate email be sent I'll probably use another helper method like CreateMultipleEmailsToMultipleRecipients. I guess you should review your naming convention so it will be obvious what it will do.
Is such behavior is expected one or that is an issue?

Below is a code with causes such behavior:

           var from = new EmailAddress(emailConfiguration.EmailAddress, emailConfiguration.Name);
           var tos = emails.Distinct(StringComparer.CurrentCultureIgnoreCase).Select(c => new EmailAddress(c)).ToList();
           var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, tos, subject, "", htmlContent);
           msg.AddCcs(ccs.Distinct(StringComparer.CurrentCultureIgnoreCase).Except(emails, 
                   StringComparer.CurrentCultureIgnoreCase).Select(c => new EmailAddress(c)).ToList());
           }

            client.SendEmailAsync(msg);

And code which works for us:

           var from = new EmailAddress(emailConfiguration.EmailAddress, emailConfiguration.Name);
           var tos = emails.Distinct(StringComparer.CurrentCultureIgnoreCase).Select(c => new EmailAddress(c)).ToList();
           var msg = MailHelper.CreateSingleEmailToMultipleRecipients(from, tos, subject, "", htmlContent, true);
           msg.AddCcs(ccs.Distinct(StringComparer.CurrentCultureIgnoreCase).Except(emails, 
                   StringComparer.CurrentCultureIgnoreCase).Select(c => new EmailAddress(c)).ToList());
           }

### Technical details:
* sendgrid-csharp version: 9.21.0
* csharp version: C#8
* .net version: .Net Core 3.1
@eshanholtz
Copy link
Contributor

Hi @D1mitry, I recommend taking a look at my response to a similar question. Essentially, if the specific helper function doesn't quite satisfy what behavior you're looking for, you may have to construct the email yourself. The documentation provides some walkthroughs on how to construct different types of Personalization payloads. Please use our troubleshooting guide for instructions on how to view the request body before sending emails.

@eshanholtz eshanholtz added status: waiting for feedback waiting for feedback from the submitter type: getting started question while getting started type: question question directed at the library labels Oct 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for feedback waiting for feedback from the submitter type: getting started question while getting started type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

3 participants