← Back to blog

FusionAuth Transactional Email API (2026): Notify That a New Recovery Code Set Was Generated with POST /emails

Send a “new recovery code set was generated” notice from your server after a FusionAuth webhook with Rovela’s HTTP API: store the Bearer key in server env, fetch POST /emails, and set an Idempotency-Key. The trigger is described generically — this guide does not invent a FusionAuth event name. Not a verification-code, magic-link, password-reset, or welcome tutorial, and not an invented Rovela-FusionAuth plugin.

Updated November 10, 2026
FusionAuth Transactional Email API (2026): Notify That a New Recovery Code Set Was Generated with POST /emails

A recovery-codes notice is not an OTP tutorial, and it is not an Auth0 or Kinde rewrite

When a user generates a new set of recovery codes in your FusionAuth-backed app — after losing a device, rotating two-factor methods, or being asked to refresh codes in settings — they should get a security notice: “A new recovery code set was generated,” plus a link to review their security settings. That send is transactional email. It is not a newsletter, not a broadcast, and it is not a rewrite of the Auth0, Clerk, Stytch, WorkOS, Descope, Kinde, Firebase Auth, Amazon Cognito, Supabase, Better Auth, Lucia, SuperTokens, or Auth.js / NextAuth guides. Those tutorials already exist. This one is your server handling a FusionAuth webhook and then queueing a notice that is not a verification code, not a magic link, not a password reset, and not a welcome email.

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 Rovela fields and a generic FusionAuth webhook hand-off on purpose. FusionAuth can call your HTTP endpoint when something happens in a tenant; you verify that inbound webhook the way FusionAuth documents, then you decide whether the payload means a new recovery code set was generated. This tutorial does not invent a FusionAuth event type name — use the event type your tenant actually emits. It also does not invent a Rovela-FusionAuth plugin, an official marketplace extension, or a contacts, topics, or broadcasts product tour. The JSON body you send to Rovela is the same one 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 your webhook handler belongs on POST /emails, which is also the distinction drawn in Email API vs SMTP relay.

Your server receives a FusionAuth webhook after recovery codes are generated, then posts JSON to the email API and receives a message id

What you need before the first FusionAuth-triggered send

The first-email guide and the Quick Start are the same five steps, whether your caller is a webhook handler or any other server:

  1. Create an account. You start on the free plan, which sends real mail. There is no separate sandbox or test key.
  2. Add and verify a sending domain (a subdomain such as mail.example.com is a common choice). You cannot send from a domain you have not verified; an unverified or foreign from is 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.
  3. Create an API key. A sending_access key can send and nothing else — the right default for a production webhook handler. A full_access key can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once.
  4. Send with POST /emails.
  5. Confirm delivery in the dashboard, with GET /emails/:id or GET /emails/:id/events (those reads need full_access or a dashboard session), or with a webhook.

from is a string in the documented form "Security <security@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 a user first sees that new recovery codes were created (HTML email API).

Your server handles the FusionAuth webhook, then POST /emails

Keep the Rovela key out of the browser, out of a public repository, and out of any FusionAuth tenant setting that is widely visible. A leaked sending_access key can send mail as your domain. Store it in your server environment. FusionAuth’s own webhook secret (or whatever inbound verification FusionAuth documents for your tenant) is a separate credential. Do not mix the two, and do not assume Rovela’s delivery-webhook signature header applies to inbound FusionAuth traffic.

The handler below is deliberately generic. It assumes you have already verified the inbound FusionAuth webhook and already decided, from fields in the payload your tenant actually sends, that a new recovery code set was generated. It then uses plain fetch — still not an official SDK — to queue the notice. Do not put the recovery codes themselves in the email. The message is a security alert with a link to settings, not a channel for shipping the codes.

import http from "node:http";

const API = "https://api.rovela.dev/emails";

async function notifyRecoveryCodesGenerated({ eventId, userId, to, settingsUrl }) {
  const res = await fetch(API, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.ROVELA_API_KEY}`,
      "Content-Type": "application/json",
      "Idempotency-Key": `recovery-codes-${userId}-${eventId}`,
    },
    body: JSON.stringify({
      from: "Security <security@mail.example.com>",
      to,
      subject: "A new recovery code set was generated",
      html: `<p>A new recovery code set was generated for your account.</p><p><a href="${settingsUrl}">Review security settings</a></p>`,
      text: `A new recovery code set was generated for your account. Review security settings: ${settingsUrl}`,
      reply_to: "security@mail.example.com",
      tags: { type: "recovery_codes_generated", user_id: userId, event_id: eventId },
    }),
  });
  const body = await res.json();
  if (!res.ok) {
    throw new Error(`send failed ${res.status}: ${JSON.stringify(body)}`);
  }
  return body; // { object: "email", id: "..." }
}

http.createServer(async (req, res) => {
  if (req.method !== "POST" || req.url !== "/webhooks/fusionauth") {
    res.writeHead(404);
    res.end();
    return;
  }
  const chunks = [];
  for await (const c of req) chunks.push(c);
  const payload = JSON.parse(Buffer.concat(chunks).toString());
  // Verify the inbound FusionAuth webhook using FusionAuth's own documented
  // mechanism for your tenant. Then decide, from the payload you actually
  // received, whether a new recovery code set was generated. This guide does
  // not invent a FusionAuth event type name.
  if (!payload.recoveryCodesGenerated) {
    res.writeHead(204);
    res.end();
    return;
  }
  try {
    const sent = await notifyRecoveryCodesGenerated({
      eventId: payload.eventId,
      userId: payload.userId,
      to: payload.email,
      settingsUrl: "https://app.example.com/settings/security",
    });
    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({ emailId: sent.id }));
  } catch (err) {
    res.writeHead(500, { "Content-Type": "application/json" });
    res.end(JSON.stringify({ error: String(err.message || err) }));
  }
}).listen(Number(process.env.PORT || 8080));

The payload.recoveryCodesGenerated check in the sketch is a placeholder for your own mapping, not a documented FusionAuth field. Replace it with the event type and fields your tenant actually sends.

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 user should write back to a security mailbox rather than to the from address (email API reply-to). Put ROVELA_API_KEY in the server environment (email API authentication).

The same outbound request is a short curl you can keep in a runbook while you are wiring the handler:

curl -X POST https://api.rovela.dev/emails \
  -H "Authorization: Bearer re_your_sending_key" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: recovery-codes-usr_01J8K2-evt_01J8K2" \
  -d '{
    "from": "Security <security@mail.example.com>",
    "to": "ada@example.com",
    "subject": "A new recovery code set was generated",
    "html": "<p>A new recovery code set was generated for your account.</p><p><a href=\"https://app.example.com/settings/security\">Review security settings</a></p>",
    "text": "A new recovery code set was generated for your account. Review security settings: https://app.example.com/settings/security",
    "reply_to": "security@mail.example.com",
    "tags": {"type": "recovery_codes_generated", "user_id": "usr_01J8K2", "event_id": "evt_01J8K2"}
  }'

A successful body is {"object": "email", "id": "9f1c2e40-..."}. Persist that id next to the security event if you want a support trail; do not treat it as proof of delivery.

Idempotency, recipients, and what a 200 actually means

Webhook deliveries retry. FusionAuth (or your proxy) may POST the same event more than once if your handler timed out after Rovela had already accepted the message. Send an Idempotency-Key header (up to 256 characters) keyed to the user id and the inbound event 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 recovery-codes notice almost always has one to (the account holder). Do not fan the codes or the notice out to a shared security alias unless that alias is an intended recipient and you are willing to count it.

If you ever need to notify many independent users in one go (for example a catch-up after a handler outage), 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 security event.

template is documented as { id, variables } and is mutually exclusive with html and text. This tutorial sends both html and text so the security warning and the settings link 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 recovery-codes notice should send immediately; delaying a security alert is usually the wrong default. Related scheduling patterns, for other kinds of mail, are in scheduled email sending.

Errors you should handle in the webhook handler

Documented send errors use an envelope of { statusCode, name, message }:

  • 400 — a missing required field, a from domain that does not belong to your organization, a template that 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_access key used to read, reschedule, or cancel a message. Check the secret the handler 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).

Return a non-2xx to FusionAuth only when you want the inbound webhook retried, and only after you understand the error. A 400 from Rovela will not be fixed by a retry; log it and return 200 so the same bad payload does not loop. 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 webhook handler

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 the FusionAuth webhook handler. Subscribe to a Rovela webhook for delivery events 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.

Those delivery webhooks are outbound from Rovela. They are not the same as the inbound FusionAuth webhook that triggered the send. Verify each with the mechanism that belongs to that system.

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 security notices should send immediately.

An Auth0, Kinde, or OTP/magic-link send is a different tutorial; your server posts a recovery-codes notice with POST /emails after a FusionAuth webhook

What not to do in a FusionAuth integration

  • Do not put the Rovela key in a FusionAuth theme, a client-side login widget, or a public tenant configuration screen.
  • Do not install or advertise an official Rovela-FusionAuth plugin — there isn’t one in this guide, and inventing one would be a product claim we cannot make.
  • Do not invent a FusionAuth event type name in your runbook or in this integration. Use the event your tenant actually emits, and describe the business meaning: a new recovery code set was generated.
  • Do not send the recovery codes in the email body. The notice is that a new set was generated; the codes themselves stay in the FusionAuth-hosted flow or your own secure display, not in a mailbox.
  • Do not copy an Auth0, Kinde, or verification-code article and swap the vendor name. The story here is a recovery-codes security notice, not a login email and not an organization-invitation accept.
  • Do not send from mailbox SMTP for this. SMTP is for mail apps and mailboxes. A webhook handler should use the HTTP API.
  • Do not skip domain verification. An unverified from is 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 FusionAuth checklist

  1. Verify the sending domain and create a sending_access key (Quick Start).
  2. Put ROVELA_API_KEY and ROVELA_FROM in the webhook handler environment, not in FusionAuth themes or the browser.
  3. Verify the inbound FusionAuth webhook using FusionAuth’s documented mechanism, decide that a new recovery code set was generated, then POST https://api.rovela.dev/emails.
  4. Send both html and text, include the security settings URL, do not include the codes, and set Idempotency-Key to recovery-codes-<userId>-<eventId>.
  5. Optionally set reply_to and tags such as type=recovery_codes_generated.
  6. Handle 400, 401, and 429 from the error envelope. Confirm delivery with a Rovela webhook (signature x-resend-signature), not by polling inside the handler.
  7. 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 FusionAuth webhook you already receive, one HTTPS POST, and a security notice the user can act on.