From e963755393aa7d6b4985b2cb2ca17a1ead05f23c Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 10 Aug 2021 18:01:19 -0400 Subject: [PATCH] Set 'To' addresses on Letter email after message is prepared This works with mailgun.AddRecipientAndVariables, so we can safely send emails to a large number of recipients beyond Mailgun's 1,000-recipient limit. Ref T856 --- email.go | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/email.go b/email.go index 451f988..a007422 100644 --- a/email.go +++ b/email.go @@ -328,19 +328,6 @@ Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/un if len(subs) == 0 { return nil } - log.Info("[email] Adding %d recipient(s)", len(subs)) - for _, s := range subs { - e := s.FinalEmail(app.keys) - log.Info("[email] Adding %s", e) - err = m.AddRecipientAndVariables(e, map[string]interface{}{ - "id": s.ID, - "to": e, - "token": s.Token, - }) - if err != nil { - log.Error("Unable to add receipient %s: %s", e, err) - } - } if title != "" { title = string(`

` + p.FormattedDisplayTitle() + `

`) @@ -425,6 +412,21 @@ Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/un } m.SetHtml(html) + + log.Info("[email] Adding %d recipient(s)", len(subs)) + for _, s := range subs { + e := s.FinalEmail(app.keys) + log.Info("[email] Adding %s", e) + err = m.AddRecipientAndVariables(e, map[string]interface{}{ + "id": s.ID, + "to": e, + "token": s.Token, + }) + if err != nil { + log.Error("Unable to add receipient %s: %s", e, err) + } + } + res, _, err := gun.Send(m) log.Info("[email] Send result: %s", res) if err != nil {