// notify_drain — queue TRIGGER on `post-notifications`. Sends one email per // reader in the batch via email::send_html (relayed to Mailpit in dev). let msg = ctx.event.queue.message; if msg == () { return; } let from = vars::get("notify-from-email"); let base = vars::get("site-base-url"); let title = msg.title; let url = base + "/posts/" + msg.slug; let sent = 0; for addr in msg.emails { try { email::send_html(#{ to: addr, from: from, subject: "New post: " + title, text: "A new post was published: " + title + "\n\nRead it: " + url, html: "

" + title + "

" + "

A new post was just published on the blog.

" + "

Read it here

", }); sent += 1; } catch(e) { log::warn("notify email failed", #{ to: addr, err: "" + e }); } } log::info("sent post notifications", #{ title: title, sent: sent });