Dynamics 365





Wednesday, September 10, 2014

Send Email using Plug in in CRM 2011 dynamics c#.net

Send Email using Plug in in CRM 2011 dynamics c#.net

 

Send Email using Plug in

This Plugin explains how to send email to user.

//send mail when ratin less than 20%
                                                Guid opprid = entity.Id;
                                                Entity Opprt = service.Retrieve("new_prospect", opprid, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                                                Guid ownerId = ((EntityReference)Opprt.Attributes["ownerid"]).Id;
                                                Entity owner = service.Retrieve("systemuser", ownerId, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                                                String ownerName = (String)owner.Attributes["fullname"];
                                                Guid custId = ((EntityReference)Opprt.Attributes["ownerid"]).Id;
                                                String subject = "";
                                                subject = subject + "The following Prospect is Converted to Lead  with <b>Rating 10 %</b><br><br>";
                                                subject = subject + "<b>" + entity.Attributes["new_lastname"].ToString() + "   " + entity.Attributes["new_firstname"].ToString() + "</b>";

                                               // subject = subject + "<br>Kindly check/ensure availability of the required Products by " + dt + "<br><br>";

                                                Entity fromParty = new Entity("activityparty");
                                                fromParty["partyid"] = new EntityReference("systemuser", ownerId);
                                                Entity toParty = new Entity("activityparty");
                                                toParty["partyid"] = new EntityReference("systemuser", ownerId);

                                                Entity Email = new Entity("email");
                                                Email.Attributes["from"] = new Entity[] { fromParty };
                                                Email.Attributes["to"] = new Entity[] { toParty };
                                                Email.Attributes["subject"] = "Prospect to Lead with rating 10%";
                                                Email.Attributes["regardingobjectid"] = new EntityReference("new_prospect", opprid);
                                                Email.Attributes["description"] = subject;
                                                Email.Attributes["ownerid"] = new EntityReference("systemuser", ownerId);
                                               
                                                Guid EmailId = service.Create(Email);

                                                SendEmailRequest req = new SendEmailRequest();
                                                req.EmailId = EmailId;
                                                req.IssueSend = true;
                                                req.TrackingToken = "";
                                           
                                                SendEmailResponse res = (SendEmailResponse)service.Execute(req);


Here you CRM user should configure with Microsoft Outlook.

This will send email for who has logged in .
Please change code to get Manager of user or according to your requirement.
 


No comments:

Post a Comment