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
This commit is contained in:
Matt Baer 2021-08-10 18:01:19 -04:00
parent 2288ccf2a2
commit e963755393

View file

@ -328,19 +328,6 @@ Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/un
if len(subs) == 0 { if len(subs) == 0 {
return nil 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 != "" { if title != "" {
title = string(`<h2 id="title">` + p.FormattedDisplayTitle() + `</h2>`) title = string(`<h2 id="title">` + p.FormattedDisplayTitle() + `</h2>`)
@ -425,6 +412,21 @@ Sent to %recipient.to%. Unsubscribe: ` + p.Collection.CanonicalURL() + `email/un
} }
m.SetHtml(html) 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) res, _, err := gun.Send(m)
log.Info("[email] Send result: %s", res) log.Info("[email] Send result: %s", res)
if err != nil { if err != nil {