Exemplo n.º 1
0
        private string FormatTemplate(string template, EmailRequestModel emailRequest)
        {
            foreach (var placeholder in emailRequest.PlaceholderContent)
            {
                template = template.Replace($"%%{placeholder.Key}%%", HttpUtility.HtmlEncode(placeholder.Value));
            }

            return(template);
        }
Exemplo n.º 2
0
        public async Task <Email> BuildEmail(EmailRequestModel emailRequest)
        {
            _logger.LogInformation("Build email");

            var template = await GetTemplate(emailRequest.TemplateType);

            template = FormatTemplate(template, emailRequest);
            var emailModel = new Email
            {
                FromName   = emailRequest.SenderName,
                FromEmail  = emailRequest.SenderEmail,
                To         = emailRequest.DestinationAddress,
                SenderName = emailRequest.SenderName,
                Subject    = EmailConstants.GetSubject(emailRequest.TemplateType),
                Content    = template,
                Attachment = emailRequest.Attachment
            };

            return(emailModel);
        }
Exemplo n.º 3
0
        public async Task SendAsync(EmailRequestModel emailRequest, CancellationToken cancellationToken = default)
        {
            var email = await _emailBuilder.BuildEmail(emailRequest);

            await SendAsync(email, cancellationToken);
        }