public CreateNotification(string unsecure, string secure)
        {
            unsecureConfig = unsecure;
            secureConfig   = secure;

            config = JsonDeserializer.Parse <CreateNotificationConfig>(unsecure);
        }
        private void SendEmailNotification(string message, string locale, EntityReference user, Entity subscription, Entity notification, IOrganizationService service)
        {
            var emailNotificationsSenderText = subscription.GetAttributeValue <string>("oss_emailnotificationssender");
            var sender = string.IsNullOrEmpty(emailNotificationsSenderText) ? user : JsonDeserializer.Parse <EntityReference>(emailNotificationsSenderText);

            var email = new Entity
            {
                LogicalName = "email",
                ["from"]    = new EntityCollection(new List <Entity>
                {
                    new Entity {
                        LogicalName = "activityparty",
                        ["partyid"] = sender
                    }
                }),
                ["to"] = new EntityCollection(new List <Entity>
                {
                    new Entity {
                        LogicalName = "activityparty",
                        ["partyid"] = user
                    }
                }),
                ["regardingobjectid"] = notification.ToEntityReference(),
                ["subject"]           = "New D365 Notification",
                ["description"]       = message
            };

            if (config.Value.EmailLocaleConfig != null && config.Value.EmailLocaleConfig.ContainsKey(locale))
            {
                email["oss_htmltemplateuniquename"] = config.Value.EmailLocaleConfig[locale];
            }
            else if (config.Value.EmailLocaleConfig != null && config.Value.EmailLocaleConfig.ContainsKey("default"))
            {
                email["oss_htmltemplateuniquename"] = config.Value.EmailLocaleConfig["default"];
            }

            email.Id = service.Create(email);

            var sendRequest = new SendEmailRequest
            {
                EmailId   = email.Id,
                IssueSend = true
            };

            service.Execute(sendRequest);
        }
 public CreateNotification(string unsecure, string secure)
 {
     config = new Lazy <CreateNotificationConfig>(() => JsonDeserializer.Parse <CreateNotificationConfig>(unsecure));
 }