Skip to content

Commit

Permalink
switch to rendering newsletter for each contact
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jun 26, 2023
1 parent 80f3043 commit 00746fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions CreatorKit.Extensions/CustomEmailRunServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public async Task<object> Any(NewsletterMailRun request)
{
var newsletterDate = request.ToDate ?? DateTime.UtcNow;
var response = Renderer.CreateMailRunResponse();
var viewRequest = request.ConvertTo<RenderNewsletter>();
var bodyHtml = (string) await Gateway.SendAsync(typeof(string), viewRequest);

var mailRun = await Renderer.CreateMailRunAsync(Db, new MailRun {
Layout = "marketing",
Expand All @@ -25,13 +23,15 @@ public async Task<object> Any(NewsletterMailRun request)

foreach (var sub in await Db.GetActiveSubscribersAsync(request.MailingList))
{
var viewRequest = request.ConvertTo<RenderNewsletter>().FromContact(sub);
var bodyHtml = (string) await Gateway.SendAsync(typeof(string), viewRequest);
response.AddMessage(await Renderer.CreateMessageRunAsync(Db, new MailMessageRun
{
Message = new EmailMessage
{
To = sub.ToMailTos(),
Subject = string.Format(AppData.Info.NewsletterFmt, $"{newsletterDate:MMMM} {newsletterDate:yyyy}"),
BodyHtml = Renderer.ReplaceContactArgs(bodyHtml, sub),
BodyHtml = bodyHtml,
}
}.FromRequest(viewRequest), mailRun, sub));
}
Expand Down
4 changes: 2 additions & 2 deletions CreatorKit.Extensions/CustomRendererServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public async Task<object> Any(RenderNewsletter request)

return await Renderer.RenderToHtmlResultAsync(Db, context, request, args: new() {
["title"] = $"{toDate:MMMM} {toDate:yyyy}",
["header"] = request.Header != null ? await context.RenderScriptAsync(request.Header, Renderer.PassContactArgs) : null,
["footer"] = request.Footer != null ? await context.RenderScriptAsync(request.Footer, Renderer.PassContactArgs) : null,
["header"] = request.Header != null ? await context.RenderScriptAsync(request.Header, request.ToObjectDictionary()) : null,
["footer"] = request.Footer != null ? await context.RenderScriptAsync(request.Footer, request.ToObjectDictionary()) : null,
});
}
}

0 comments on commit 00746fd

Please sign in to comment.