From 3692853087a38c6974cc37f245a5dbf9addb049d Mon Sep 17 00:00:00 2001 From: Mia Winter Date: Wed, 14 Feb 2024 12:51:03 +0100 Subject: [PATCH] Added html partial for articles in email --- Wave/Services/EmailTemplateService.cs | 9 +++++++++ Wave/Services/SmtpEmailSender.cs | 22 ++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Wave/Services/EmailTemplateService.cs b/Wave/Services/EmailTemplateService.cs index bc12b97..9fced40 100644 --- a/Wave/Services/EmailTemplateService.cs +++ b/Wave/Services/EmailTemplateService.cs @@ -77,6 +77,15 @@ public enum Constants { FileSystem.GetEmailTemplate("default", DefaultTemplates["default"]); FileSystem.GetEmailTemplate("newsletter", DefaultTemplates["newsletter"]); FileSystem.GetEmailTemplate("welcome", DefaultTemplates["welcome"]); + FileSystem.GetPartialTemplateAsync("email-article", + """ +
+

{0}

+ {1} +

{2}...

+ Link +
+ """); } public string ApplyTokens(string template, Func replacer) { diff --git a/Wave/Services/SmtpEmailSender.cs b/Wave/Services/SmtpEmailSender.cs index 555d419..a9903cd 100644 --- a/Wave/Services/SmtpEmailSender.cs +++ b/Wave/Services/SmtpEmailSender.cs @@ -11,10 +11,11 @@ namespace Wave.Services; -public class SmtpEmailSender(ILogger logger, IOptions config, IOptions customizations, EmailTemplateService templateService) : IEmailSender, IAdvancedEmailSender { +public class SmtpEmailSender(ILogger logger, IOptions config, IOptions customizations, EmailTemplateService templateService, FileSystemService fileSystemService) : IEmailSender, IAdvancedEmailSender { private ILogger Logger { get; } = logger; private SmtpConfiguration Configuration { get; } = config.Value; private Customization Customizations { get; } = customizations.Value; + private FileSystemService FileSystemService { get; } = fileSystemService; private EmailTemplateService TemplateService { get; } = templateService; public Task SendConfirmationLinkAsync(ApplicationUser user, string email, string confirmationLink) => @@ -106,19 +107,20 @@ public Task SendEmailAsync(string email, string? name, string subject, string ht .CreateConfirmTokensAsync(subscriber.Id, "unsubscribe-welcome", TimeSpan.FromDays(30)); var host = new Uri(string.IsNullOrWhiteSpace(Customizations.AppUrl) ? "" : Customizations.AppUrl); // TODO get link + string articlePartial = (await FileSystemService.GetPartialTemplateAsync("email-article", """ +
+

{0}

+ {1} +

{2}...

+ Link +
+ """))!; var articlesHtml = new StringBuilder(""); foreach (var n in articles) { string articleLink = ArticleUtilities.GenerateArticleLink(n.Article, new Uri(Customizations.AppUrl, UriKind.Absolute)); articlesHtml.AppendFormat( - """ -
-

{0}

- {1} -

{2}

- Link -
- """, - n.Article.Title, n.Article.Author.Name, n.Article.Body[..Math.Min(100, n.Article.Body.Length)], articleLink); + articlePartial, + n.Article.Title, n.Article.Author.Name, n.Article.Body[..Math.Min(250, n.Article.Body.Length)], articleLink); } string logo = !string.IsNullOrWhiteSpace(Customizations.LogoLink)