Added reply-to header to newsletter mails where author has ContactEmail set
This commit is contained in:
		
							parent
							
								
									9d528dc8f2
								
							
						
					
					
						commit
						4355a61483
					
				|  | @ -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) { | ||||
|  |  | |||
|  | @ -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); | ||||
| 					} | ||||
| 				} | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue