private string FormatTemplate(string template, EmailRequestModel emailRequest) { foreach (var placeholder in emailRequest.PlaceholderContent) { template = template.Replace($"%%{placeholder.Key}%%", HttpUtility.HtmlEncode(placeholder.Value)); } return(template); }
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); }
public async Task SendAsync(EmailRequestModel emailRequest, CancellationToken cancellationToken = default) { var email = await _emailBuilder.BuildEmail(emailRequest); await SendAsync(email, cancellationToken); }