protected virtual string Merge(string template, MergeDictionary values)
        {
            foreach (string key in values.Keys)
            {
                template = template.Replace("{{" + key + "}}", values[key], StringComparison.InvariantCultureIgnoreCase);
            }

            return(template);
        }
        public async Task <Email> GenerateEmail(string emailTemplate, string recipientEmail, MergeDictionary replaceDictionary, CultureInfo culture = null)
        {
            if (string.IsNullOrWhiteSpace(BaseDirectory))
            {
                throw new InvalidOperationException("BaseDirectory is not setup!");
            }

            var settings = await LoadSettings(emailTemplate);

            string plainTextTemplateFile = await LoadTemplate("MessageBody.txt", emailTemplate, culture);

            string htmlTemplateFile = await LoadTemplate("MessageBody.html", emailTemplate, culture);

            Email result = new();

            result.Subject         = settings.EmailSubject;
            result.FromEmail       = settings.FromEmail;
            result.FromDisplayName = settings.FromDisplayName;
            result.ToEmail         = recipientEmail;

            if (replaceDictionary.ContainsKey("ToDisplayName"))
            {
                result.ToDisplayName = replaceDictionary["ToDisplayName"];
            }

            if (!string.IsNullOrWhiteSpace(plainTextTemplateFile))
            {
                result.BodyPlainText = Merge(plainTextTemplateFile, replaceDictionary);
            }

            if (!string.IsNullOrWhiteSpace(htmlTemplateFile))
            {
                result.BodyHtml = Merge(htmlTemplateFile, replaceDictionary);
            }

            return(result);
        }