public static Task <MailMessage> RenderEmailAsync(this ITemplateEngine templateEngine, string path, object viewBag = null,
                                                          CultureInfo culture = null)
        {
            Contract.Requires <ArgumentNullException>(templateEngine != null);
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(path));
            Contract.Requires <NotSupportedException>(templateEngine.GetType() == typeof(RazorTemplateEngine), "Only razor engine is supported.");

            return(templateEngine.RenderAsync(path, renderer: new EmailRenderer(), viewBag: viewBag, culture: culture));
        }
Exemple #2
0
        /// <inheritdoc />
        public async Task <string> GenerateEmailBody <T>(MessageTemplate template, T model)
        {
            template.ThrowIfNull(nameof(template));

            logger.LogInformation($"Start generate email body by template:{template.Name}, model: {model?.ToJson()}, parent template:{template.Parent}");

            var parentTemplate = await GetParentTemplate(template);

            VerifyTemplateAndParentTemplate(template, parentTemplate);

            ITemplateEngine templateEngine = GetTemplateEngine(template.EngineType);

            templateEngine.AddParentTemplate(parentTemplate);

            logger.LogInformation($"Starting async render template with model. Type template engine: {templateEngine.GetType().Name}");

            return(await templateEngine.RenderAsync(template, model));
        }