Added reply-to header to newsletter mails where author has ContactEmail set

This commit is contained in:
Mia Rose Winter 2024-02-19 00:31:40 +01:00
parent 9d528dc8f2
commit 4355a61483
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
2 changed files with 9 additions and 4 deletions

View file

@ -19,16 +19,18 @@ public class EmailFactory(IOptions<Customization> customizations, EmailTemplateS
return new StaticEmail(receiverMail, receiverName, subject, title, body, FrozenDictionary<string, string>.Empty);
}
public async ValueTask<IEmail> CreateSubscribedEmail(EmailSubscriber subscriber, string browserLink, string subject, string title, string bodyHtml, string role = "unknown") {
public async ValueTask<IEmail> CreateSubscribedEmail(EmailSubscriber subscriber, string browserLink, string subject, string title, string bodyHtml, string role = "unknown", string? replyTo = null) {
(string host, string logo) = GetStaticData();
string unsubscribeLink = await GetUnsubscribeLink(host, subscriber.Id, role);
string body = await TemplateService.NewsletterAsync(host, browserLink, logo, title, bodyHtml, unsubscribeLink);
return new StaticEmail(subscriber.Email, subscriber.Name, subject, title, body, new Dictionary<string, string>{
var headers = new Dictionary<string, string>{
{HeaderId.ListUnsubscribe.ToHeaderName(), $"<{unsubscribeLink}>"},
{HeaderId.ListUnsubscribePost.ToHeaderName(), "One-Click"}
}.ToFrozenDictionary());
};
if (!string.IsNullOrWhiteSpace(replyTo)) headers.Add(HeaderId.ReplyTo.ToHeaderName(), replyTo);
return new StaticEmail(subscriber.Email, subscriber.Name, subject, title, body, headers.ToFrozenDictionary());
}
public async ValueTask<IEmail> CreateWelcomeEmail(EmailSubscriber subscriber, IEnumerable<EmailNewsletter> articles, string subject, string title, string bodyHtml) {

View file

@ -35,6 +35,9 @@ public class NewsletterBackgroundService(ILogger<NewsletterBackgroundService> lo
Logger.LogInformation("Cancellation requested, skipping processing '{title}'.", newsletter.Article.Title);
return;
}
string replyTo = "";
if (!string.IsNullOrWhiteSpace(newsletter.Article.Author.ContactEmail))
replyTo = $"{newsletter.Article.Author.Name} <{newsletter.Article.Author.ContactEmail}>";
Logger.LogInformation("Processing '{title}'.", newsletter.Article.Title);
// set newsletter to send first, so we don't spam people
@ -53,7 +56,7 @@ public class NewsletterBackgroundService(ILogger<NewsletterBackgroundService> lo
foreach (var subscriber in subscribers) {
var email = await factory.CreateSubscribedEmail(subscriber, articleLink, newsletter.Article.Title,
newsletter.Article.Title, newsletter.Article.BodyHtml, newsletter.Id.ToString());
newsletter.Article.Title, newsletter.Article.BodyHtml, newsletter.Id.ToString(), replyTo);
await client.SendEmailAsync(email);
}
}