web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Send Mails to Multiple mail addresses in TO using C# workflow activity in CRM 2016 Onpremise

(0) ShareShare
ReportReport
Posted on by 2,667

Hi All,

Need help on sending mails to multiple mail addresses in To section but always its taking only one & keeping mails in draft status.What could be the way how can we directly pass list of mail addresss in toParty["partyid"] as its not taking while am adding list customeEMailAddressidList which is :  toParty["partyid"] = new EntityReference("mdc_customemailaddresses", customeEMailAddressidList );

results.Entities.Count am getting 4 mail addresses ids so here need to send mail 4 mail addresses at once.

Below code am using :

//Guid customeEMailAddressid = new Guid();
                            List<Guid> customeEMailAddressidList = new List<Guid>();
                            //fyimembers = grievence.Attributes.Contains("mdc_fyimembers") ? grievence.GetAttributeValue<string>("mdc_fyimembers") : null;
                            //string[] fyimember = fyimembers.Split(',');
 
                            QueryExpression query = new QueryExpression("mdc_customemailaddresses");
                            query.ColumnSet = new ColumnSet("mdc_customemailaddressesid");
                            query.Criteria.AddCondition("mdc_pdgrievanceid"ConditionOperator.Equal, entityID);
                            EntityCollection results = service.RetrieveMultiple(query);
 
                            if (results.Entities.Count > 0)
                            {
                                foreach (var item in results.Entities)
                                {
                                    customeEMailAddressidList.Add((Guid)item.Attributes["mdc_customemailaddressesid"]);
                                    //SendMail(service, entityID, ownerId, customeEMailAddressid, casenumber, employeeName, caseSummary, platformName, unit);
                                }
                            }
 
                            subject = "FYI – Performance Grievance Recommendations: " + employeeName + "-" + casenumber;
                            //string discription = "This is for your Information test mail";
                            StringBuilder discription = new StringBuilder();
                            discription.Append("Dear All,</br></br>");
                            discription.Append("The case number " + casenumber + " with the below details has been reviewed and closed.");
                            //discription.Append("<html><body><a href=" + URL + "+>Approve/Reject</a></body></html> ");
                            discription.Append("<p>Summary of case: " + caseSummary + "</br></p>");
                            discription.Append("<p>Platform       : " + platformName + "</br></p>");
                            discription.Append("<p>Unit           : " + unit + "</br></p>");
                            discription.Append("<p>Regards,</br>MyVoice Team</p>");
                            discription.ToString();
                            Entity fromParty = new Entity("activityparty");
                            fromParty["partyid"] = new EntityReference("systemuser", ownerId);
 
                            Entity toParty = new Entity("activityparty");
                            if (customeEMailAddressidList.Count > 0)
                            {
                                foreach (var item in customeEMailAddressidList)
                                {
                                    toParty["partyid"] = new EntityReference("mdc_customemailaddresses", item);
                                }
                            }
                            //string[] splitEmails = fyimembers.Split(',');
                            //EntityCollection activityParties = new EntityCollection();
                            //foreach (string emailAddress in splitEmails)
                            //{
                            //    Entity toParty = new Entity("activityparty");
                            //    toParty["addressused"] = emailAddress;
                            //    activityParties.Entities.Add(toParty);
                            //}
 
                            Entity Email = new Entity("email");
                            Email.Attributes["from"] = new Entity[] { fromParty };
                            Email.Attributes["to"] = new Entity[] { toParty };
                            //Email.Attributes["to"] = activityParties;
                            Email.Attributes["subject"] = subject;
                            Email.Attributes["regardingobjectid"] = new EntityReference("mdc_pdgrievance", entityID);
                            Email.Attributes["description"] = discription.ToString();
                            Email.Attributes["ownerid"] = new EntityReference("systemuser", ownerId);
                            Guid EmailId = service.Create(Email);
                        }
Please let me know if anyone has idea on this,it would be helpful.
Thanks,
Jharana
I have the same question (0)
  • Suggested answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    HI,

    You should use EntityCollection to add multiple email address in To Activity Party.

    Use below code .

    EntityCollection ecToActivityParties=new EntityCollection();

                               if (customeEMailAddressidList.Count > 0)

                               {

                                   foreach (var item in customeEMailAddressidList)

                                   {

                                        Entity toParty = new Entity("activityparty");

                                       toParty["partyid"] = new EntityReference("mdc_customemailaddresses", item);

                                       ecToActivityParties.Entities.Add(toParty );

                                   }

                               }

    Now use ecToActivityParties to set to field in email

    Email.Attributes["to"] =ecToActivityParties ;

    blog.magnetismsolutions.com/.../working-with-dynamics-crm-activity-party-lists-in-c--plugins

    Email status is draft because you are just creating Email entity record but not sending from your c# code.

    You will need to use below code to send email once you create the record

    // Use the SendEmail message to send an e-mail message.

                       var sendEmailreq = new SendEmailRequest

                       {

                           EmailId = emailId,

                           TrackingToken = "",

                           IssueSend = true

                       };

                       var sendEmailresp = (SendEmailResponse)service.Execute(sendEmailreq);

    github.com/.../SampleProgram.cs

    Please mark my answer verified if i were helpful

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 98 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 72

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans