/// <summary>
        /// Sends an email using the `MailKit` library.
        /// This method converts a razor template file to an string and then uses it as the email's message.
        /// </summary>
        public async Task SendEmailAsync <T>(
            SmtpConfig smtpConfig,
            IEnumerable <MailAddress> emails,
            string subject,
            string viewNameOrPath,
            T viewModel,
            IEnumerable <MailAddress>?blindCarpbonCopies = null,
            IEnumerable <MailAddress>?carpbonCopies      = null,
            IEnumerable <MailAddress>?replyTos           = null,
            DelayDelivery?delayDelivery          = null,
            IEnumerable <string>?attachmentFiles = null,
            MailHeaders?headers = null,
            bool shouldValidateServerCertificate = true)
        {
            var message = await _viewRendererService.RenderViewToStringAsync(viewNameOrPath, viewModel);

            await SendEmailAsync(
                smtpConfig,
                emails,
                subject,
                message,
                blindCarpbonCopies,
                carpbonCopies,
                replyTos,
                delayDelivery,
                attachmentFiles,
                headers,
                shouldValidateServerCertificate);
        }
        public async Task <IActionResult> Render()
        {
            var content = await _viewRendererService.RenderViewToStringAsync(
                viewNameOrPath : "~/Views/EmailTemplates/_Template1.cshtml",
                model : new EmailTemplateViewModel
            {
                EmailSignature = "DNT"
            });

            return(Content(content));
        }
        /// <summary>
        /// Sends an email using the `MailKit` library.
        /// This method converts a razor template file to an string and then uses it as the email's message.
        /// </summary>
        public async Task SendEmailAsync <T>(
            SmtpConfig smtpConfig,
            IEnumerable <MailAddress> emails,
            string subject,
            string viewNameOrPath,
            T viewModel,
            DelayDelivery delayDelivery          = null,
            IEnumerable <string> attachmentFiles = null,
            MailHeaders headers = null)
        {
            var message = await _viewRendererService.RenderViewToStringAsync(viewNameOrPath, viewModel);

            await SendEmailAsync(smtpConfig, emails, subject, message, delayDelivery, attachmentFiles, headers);
        }
Example #4
0
        public async Task SendEmailAsync <T>(string email, string subject, string viewNameOrPath, T model)
        {
            var message = await _viewRendererService.RenderViewToStringAsync(viewNameOrPath, model).ConfigureAwait(false);

            await SendEmailAsync(email, subject, message).ConfigureAwait(false);
        }