Send email to shared users RRS feed

  • Question

  • How can I send emails to users who have been shared a record.

    Majid G
    Monday, August 11, 2008 2:10 PM


  • No sorry, but you can check the SDK, I am sure that will point you in the right direction. 


    Best Regards,

    Tuesday, August 12, 2008 5:00 PM

All replies

  • You can use a workflow to send an automated response when the record is shared.  There are several options but a quick fix is to set a field value with the user e-mail address and update that address when the record is shared.  The workflow watches the field for a change and when it notices the change it sends the e-mail to the e-mail address in the field.


    The above is only one suggestion as there are several possible ways to get this done.


    Best Regards,

    Monday, August 11, 2008 5:22 PM
  • Thanks Edwards,

    But How do we capture the User names (& email IDs) when the record is shared to one or multiple users?

    Majid G
    Tuesday, August 12, 2008 9:11 AM
  • One way to do this is to add the text field to the form and format the field so it concantenates the e-mail addresses with a semicolon between them.  That way when you update the To field in the e-mail it will be formatted correctly for the send. 


    I can test some other options when I have time as this is only one possible option to let you know it is possible.


    Thank you,



    Tuesday, August 12, 2008 1:06 PM
  • Edwards,

    Do you have any code snippet (Java Script) for capturing the shared user names, email id and put it in the email attribute on the CRM form?
    Tuesday, August 12, 2008 4:02 PM
  • No sorry, but you can check the SDK, I am sure that will point you in the right direction. 


    Best Regards,

    Tuesday, August 12, 2008 5:00 PM
  • Does anyone have any SDK solution for this? I looked in the SDK examples I couldn't relate to anything like this. Based on Donna's suggestion, one has to know how to get the user's id and email from the shared dialog and output it into the new text field separated by a semicolon so that it can be used by the workflow for sending out email. This sounds more complicated than a SDK solution.

    If anyone have a SDK solution to use a custom workflow to send email out to the shared users every time a record is shared. This way a shared user is notified when someone shares a record him.  Thanks!

    Tuesday, February 2, 2010 4:13 AM
  • Hi ,

    you can use this way to send an email to the users with whom the lead is shared by writing a plugin for ms crm 2011 and trigerring it on GrantAccess.


    namespace ShareMail
        public class SendEmailOnAccessRights: IPlugin
            public void Execute(IServiceProvider serviceProvider)

                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                 // Obtain the target entity from the input parmameters.                        
                string body = "The following lead is shared with you";
                string sub = "Lead Shared";  

                if ((context.MessageName != "GrantAccess" || context.MessageName != "RevokeAccess") && context.Stage != 10 && context.PrimaryEntityName != "lead")
                { return; }

                IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                IOrganizationService service = factory.CreateOrganizationService(context.UserId);

                EntityReference entity = (EntityReference)context.InputParameters["Target"];
                string id = entity.Id.ToString();        

                if (context.InputParameters.Contains("PrincipalAccess"))
                    PrincipalAccess principal = context.InputParameters["PrincipalAccess"] as PrincipalAccess;
                    EntityReference sharedUser = principal.Principal;
                    AccessRights accessRights = principal.AccessMask;

                if (context.InputParameters.Contains("Revokee"))
                    EntityReference revokedUser = context.InputParameters["Revokee"] as EntityReference;

                SendEmail(service, (context.InputParameters["PrincipalAccess"] as PrincipalAccess).Principal.Id, context.UserId, new Guid(id), body, sub);         

            private void SendEmail(IOrganizationService service, Guid recieverUserId, Guid senderUserId, Guid regardingObjectId, string emailBody, string emailSubject)
                Entity email = new Entity();
                email.LogicalName = "email";

     //Set regarding object property (i.e. The entity record, which u want this email associated with)

                EntityReference regardingObject = new EntityReference("lead", regardingObjectId);
                email.Attributes.Add("regardingobjectid", regardingObject);
                //Defining Activity Parties (starts)
                EntityReference from = new EntityReference("systemuser", senderUserId);
                EntityReference to = new EntityReference("systemuser", recieverUserId);
                //Derive from party
                Entity fromParty = new Entity("activityparty");
                fromParty.Attributes.Add("partyid", from);
                //Derive to party
                Entity toParty = new Entity("activityparty");
                toParty.Attributes.Add("partyid", to);
                EntityCollection collFromParty = new EntityCollection();
                collFromParty.EntityName = "systemuser";
                EntityCollection collToParty = new EntityCollection();
                collToParty.EntityName = "systemuser";
                email.Attributes.Add("from", collFromParty);
                email.Attributes.Add("to", collToParty);
                //Defining Activity Parties (ends)
                //Set subject & body properties
                email.Attributes.Add("subject", emailSubject);
                email.Attributes.Add("description", emailBody);
                //Create email activity
                Guid emailID = service.Create(email);
                //Sending email
                SendEmailRequest reqSendEmail = new SendEmailRequest();
                reqSendEmail.EmailId = emailID;//ID of created mail
                reqSendEmail.TrackingToken = "";
                reqSendEmail.IssueSend = true;
                SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);

    Monday, April 30, 2012 9:09 AM