protected override void Execute(CodeActivityContext executionContext)
        {
            ITracingService             tracer         = executionContext.GetExtension <ITracingService>();
            IWorkflowContext            context        = executionContext.GetExtension <IWorkflowContext>();
            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>();
            IOrganizationService        service        = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                EntityReference emailToSend    = EmailToSend.Get(executionContext);
                EntityReference recipientQueue = RecipientQueue.Get(executionContext);
                bool            sendEmail      = SendEmail.Get(executionContext);
                bool            includeOwner   = IncludeOwner.Get(executionContext);

                List <Entity> toList = new List <Entity>();

                Entity email = RetrieveEmail(service, emailToSend.Id);

                if (email == null)
                {
                    UsersAdded.Set(executionContext, 0);
                    return;
                }

                //Add any pre-defined recipients specified to the array
                foreach (Entity activityParty in email.GetAttributeValue <EntityCollection>("to").Entities)
                {
                    toList.Add(activityParty);
                }

                bool             is2011 = Is2011(service);
                EntityCollection users  = is2011 ? GetQueueOwner(service, recipientQueue.Id) : GetQueueMembers(service, recipientQueue.Id);

                if (!is2011)
                {
                    if (includeOwner)
                    {
                        users.Entities.AddRange(GetQueueOwner(service, recipientQueue.Id).Entities);
                    }
                }

                toList = ProcessUsers(users, toList);

                //Update the email
                email["to"] = toList.ToArray();
                service.Update(email);

                //Send
                if (sendEmail)
                {
                    SendEmailRequest request = new SendEmailRequest
                    {
                        EmailId       = emailToSend.Id,
                        TrackingToken = string.Empty,
                        IssueSend     = true
                    };

                    service.Execute(request);
                }

                UsersAdded.Set(executionContext, toList.Count);
            }
            catch (Exception e)
            {
                throw new InvalidPluginExecutionException(e.Message);
            }
        }
        protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }

            EntityReference emailToSend    = EmailToSend.Get(context);
            EntityReference recipientQueue = RecipientQueue.Get(context);
            bool            sendEmail      = SendEmail.Get(context);
            bool            includeOwner   = IncludeOwner.Get(context);

            List <Entity> toList = new List <Entity>();

            Entity email = RetrieveEmail(localContext.OrganizationService, emailToSend.Id);

            if (email == null)
            {
                UsersAdded.Set(context, 0);
                return;
            }

            //Add any pre-defined recipients specified to the array
            foreach (Entity activityParty in email.GetAttributeValue <EntityCollection>("to").Entities)
            {
                toList.Add(activityParty);
            }

            bool             is2011 = Is2011(localContext.OrganizationService);
            EntityCollection users  = is2011
                ? GetQueueOwner(localContext.OrganizationService, recipientQueue.Id)
                : GetQueueMembers(localContext.OrganizationService, recipientQueue.Id);

            if (!is2011)
            {
                if (includeOwner)
                {
                    users.Entities.AddRange(GetQueueOwner(localContext.OrganizationService, recipientQueue.Id).Entities);
                }
            }

            toList = ProcessUsers(users, toList);

            //Update the email
            email["to"] = toList.ToArray();
            localContext.OrganizationService.Update(email);

            //Send
            if (sendEmail)
            {
                SendEmailRequest request = new SendEmailRequest
                {
                    EmailId       = emailToSend.Id,
                    TrackingToken = string.Empty,
                    IssueSend     = true
                };

                localContext.OrganizationService.Execute(request);
            }

            UsersAdded.Set(context, toList.Count);
        }