KeystoneJS Transactional Email API (2026): Notify That a Comment Was Published from a Hook with POST /emails
Send a “your comment was published” notice from a Keystone afterOperation hook with Rovela’s HTTP API: a Bearer key from process env, plain fetch to POST /emails, and an Idempotency-Key. Not a Strapi, Payload, or Directus rewrite, and not an invented official Keystone plugin.
A comment-published notice is not a Strapi, Payload, or Directus tutorial
When a moderator publishes a comment on your site — a product question that left review, a docs annotation, a community reply — the author needs a message that the comment is live: “Your comment was published,” plus a permalink. That send is transactional email. It is not a newsletter, not a broadcast, and it is not a rewrite of the Strapi transactional email, Payload CMS transactional email, or Directus transactional email guides. Those tutorials already exist, and they use a different CMS hook or Flow model. This one is a Keystone list hook (afterOperation) that fires after the comment is already marked published.
Rovela’s Email API is a single HTTPS call for that work. There is no client library to install. The base URL is https://api.rovela.dev. You authenticate with Authorization: Bearer re_… (Authentication) and queue a message with POST /emails. The response is a message id. HTTP 200 means the message was accepted and queued, not that it has already arrived (Quick Start).
This guide stays inside documented Keystone hooks and documented Rovela fields on purpose. The hook runs on the server and uses plain fetch. It does not invent an official Rovela-Keystone plugin, a marketplace extension, or a contacts, topics, or broadcasts product tour. The JSON body and headers are the same ones any runtime can send.
If you are still choosing between HTTP and SMTP, read Email API vs SMTP. Rovela’s SMTP is mailbox SMTP for mail apps (mx.rovela.dev:465, a device credential, send-as-self, 30 messages a minute from one client address). Programmatic volume from a Keystone hook belongs on POST /emails, which is also the distinction drawn in Email API vs SMTP relay.
What you need before the first Keystone send
The first-email guide and the Quick Start are the same five steps, whether your caller is a Keystone hook or any other server:
- Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
- Add and verify a sending domain (a subdomain such as
mail.example.comis a common choice). You cannot send from a domain you have not verified; an unverified or foreignfromis refused with a 400 that names the domain. The dashboard asks for four DNS records — SPF, DKIM, DMARC, and return-path. See the domain setup guide and what domain email is. - Create an API key. A
sending_accesskey can send and nothing else — the right default for a production Keystone process. Afull_accesskey can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once. - Send with
POST /emails. - Confirm delivery in the dashboard, with
GET /emails/:idorGET /emails/:id/events(those reads needfull_accessor a dashboard session), or with a webhook.
from is a string in the documented form "Comments <comments@yourdomain.com>". The address must sit on a verified sending domain. That is the same rule that makes domain email trustworthy: you prove you control the domain before you speak as it. How the display name and the address work is covered in the From name guide.
At least one of html, text, or template is required. Send both html and text where you can — many clients preview the text part, which is often where an author first sees that the comment actually went live (HTML email API).
A Keystone afterOperation hook
Keep the key out of the Admin UI browser, out of a public repository, and out of client-side Keystone custom fields. A leaked sending_access key can send mail as your domain. Store it in the Keystone process environment and read it only inside the hook.
Keystone lists can declare hooks such as afterOperation. Use that hook on your Comment list (or whatever you named the collection). Fire the send only on the transition that matters: an update (or create) that leaves the comment in a published state, when the previous state was not published. Do not send on every edit to the body, and do not send from a resolveInput hook that still might roll back.
A hook that matches the Emails API looks like this (plain fetch, still not an official SDK):
// lists/Comment.ts — sketch of a Keystone list hook
async function notifyCommentPublished({ commentId, to, permalink }) {
const res = await fetch("https://api.rovela.dev/emails", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.ROVELA_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": `comment-published-${commentId}`,
},
body: JSON.stringify({
from: "Comments <comments@mail.example.com>",
to,
subject: "Your comment was published",
html: `<p>Your comment was published.</p><p><a href="${permalink}">View the comment</a></p>`,
text: `Your comment was published. View it: ${permalink}`,
reply_to: "moderators@mail.example.com",
tags: { type: "comment_published", comment_id: commentId },
}),
});
const body = await res.json();
if (!res.ok) {
throw new Error(`send failed ${res.status}: ${JSON.stringify(body)}`);
}
return body; // { object: "email", id: "..." }
}
export const commentHooks = {
afterOperation: async ({ operation, item, originalItem }) => {
const nowPublished = item?.status === "published";
const wasPublished = originalItem?.status === "published";
if (!nowPublished || wasPublished) return;
if (operation !== "create" && operation !== "update") return;
await notifyCommentPublished({
commentId: String(item.id),
to: item.authorEmail,
permalink: `https://app.example.com/comments/${item.id}`,
});
},
};
Wire commentHooks into the hooks field of your Comment list configuration the way your Keystone version already documents. The important part is server-side execution and a stable idempotency key, not a fictional plugin name.
tags are documented as arbitrary labels and are returned with the message, which makes later debugging in the dashboard or in a webhook payload much easier (email API tags). reply_to is optional; use it when the author should write back to a moderation mailbox rather than to the from address (email API reply-to). Put ROVELA_API_KEY in the Keystone process environment (email API authentication).
The same request is a short curl you can keep in a runbook while you are wiring the hook:
curl -X POST https://api.rovela.dev/emails \
-H "Authorization: Bearer re_your_sending_key" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: comment-published-cmt_01J8K2" \
-d '{
"from": "Comments <comments@mail.example.com>",
"to": "ada@example.com",
"subject": "Your comment was published",
"html": "<p>Your comment was published.</p><p><a href=\"https://app.example.com/comments/cmt_01J8K2\">View the comment</a></p>",
"text": "Your comment was published. View it: https://app.example.com/comments/cmt_01J8K2",
"reply_to": "moderators@mail.example.com",
"tags": {"type": "comment_published", "comment_id": "cmt_01J8K2"}
}'
A successful body is {"object": "email", "id": "9f1c2e40-..."}. Persist that id next to the Keystone item if you want a support trail; do not treat it as proof of delivery.
Idempotency, recipients, and what a 200 actually means
Hooks can run twice. A process restart, a retried GraphQL mutation, or an Admin UI save that is submitted again can post the same publish transition more than once. Send an Idempotency-Key header (up to 256 characters) keyed to the comment id. A retry of the same request within 24 hours returns the original response instead of sending again (idempotency).
A message may address at most 50 recipients across to, cc, and bcc combined. That is the transport’s limit, not a plan limit, and it is checked before the request is accepted. Quota is charged per recipient, not per message — cc and bcc count the same as to. A comment-published notice almost always has one to (the author). If you also notify a watching moderator, remember that they count.
If you ever need to notify many independent authors in one go (for example a moderator published a backlog of comments), POST /emails/batch accepts up to 100 messages, each with the same schema. Two fields are rejected rather than ignored: template and topic_id. Send those through POST /emails. See the batch example and the batch transactional email guide. You do not need a batch for a single comment.
template is documented as { id, variables } and is mutually exclusive with html and text. This tutorial sends both html and text so the published state and the permalink are visible in the notification preview. If you later switch to a stored template, use POST /emails (not batch) and follow the Templates API and the templates guide.
scheduled_at is a documented ISO 8601 timestamp in the future. A published-comment notice should send immediately; if you later add a “your comment will be unpublished in 24 hours” warning, that is a different message with its own idempotency key. Related patterns are in scheduled email sending.
Errors you should handle in the hook
Documented send errors use an envelope of { statusCode, name, message }:
- 400 — a missing required field, a
fromdomain that does not belong to your organization, atemplatethat does not exist, or more than 50 recipients on one message. Fix the payload; retrying the same body will fail the same way. - 401 — a missing or invalid credential, or a
sending_accesskey used to read, reschedule, or cancel a message. Check the secret the Keystone process is actually reading. - 429 — rate limit exceeded. Each message in a batch counts individually. Back off and retry with the same
Idempotency-Key(email API retries, rate limits).
Surface those errors in Keystone server logs so a bad key or a typo in from is visible on the mutation, not silent. Whether a failed send should fail the Admin UI save is your product decision; many teams log the error and keep the published state, then retry with the same idempotency key. Broader patterns are in Email API error handling. Domain management endpoints such as GET /domains return 403 for a sending_access key — that is expected; leave domain work to the dashboard or a full_access key (Domains API, sending domains API).
Delivery is asynchronous — do not poll from the hook
A 200 from POST /emails means accepted for delivery, not delivered. Reading GET /emails/:id or GET /emails/:id/events needs a full_access key or a dashboard session; a sending_access key cannot do it, and you should not add a polling loop inside afterOperation. Subscribe to a webhook instead, and verify the signature header x-resend-signature as documented in webhook security and signature verification. Event names include accepted, delivered, opened, clicked, bounced, or failed. For a single message you can also use the email delivery status API or the dashboard from a support session.
POST /emails/:id/cancel can cancel a message that has not been sent yet, which is relevant if you used scheduled_at. Reading, rescheduling, and cancelling need full_access or a dashboard session. A request body for rescheduling is not documented here, so this guide does not invent one. Everyday comment notices should send immediately.
What not to do in a Keystone project
- Do not put the Rovela key in a public
.envexample, a client-side custom Admin component, or a list field that the Admin UI can read back. - Do not install or advertise an official Rovela-Keystone plugin — there isn’t one in this guide, and inventing one would be a product claim we cannot make.
- Do not copy the Strapi, Payload, or Directus article and swap the CMS name. The hook model is different, and the story here is a published comment, not an approval or a generic “item was created” blast.
- Do not send from mailbox SMTP for this. SMTP is for mail apps and mailboxes. A Keystone hook should use the HTTP API.
- Do not skip domain verification. An unverified
fromis refused. If you send on behalf of several tenants, a key restricted to a single domain limits the blast radius of a leak (Email API for multi-tenant SaaS).
A compact Keystone checklist
- Verify the sending domain and create a
sending_accesskey (Quick Start). - Put
ROVELA_API_KEYandROVELA_FROMin the Keystone process environment, not in the Admin UI. - Trigger
afterOperationon the publish transition, thenPOST https://api.rovela.dev/emails. - Send both
htmlandtext, include the comment permalink, and setIdempotency-Keytocomment-published-<id>. - Optionally set
reply_toandtagssuch astype=comment_published. - Handle 400, 401, and 429 from the error envelope. Confirm delivery with a webhook, not by polling inside the hook.
- If you are comparing providers, the existing pages are Rovela vs Mailgun, vs Amazon SES, vs Postmark, vs SendGrid, vs Resend, and vs Brevo. For the HTTP shape itself, see the transactional email API, the curl sending guide, and the HTTP email API overview. For other notification patterns, see the email notification API guide.
That is the whole integration: a Keystone hook you already run, one HTTPS POST, and a comment the author can open.