← Back to blog

Auth0 Transactional Email API (2026): Warn About a New Device Sign-In from an Action with POST /emails

Send a new-device sign-in warning from an Auth0 Action (for example post-login) with Rovela’s HTTP API: store the Bearer key as an Action secret, fetch POST /emails, and set an Idempotency-Key. Not a verification-code, magic-link, password-reset, or welcome tutorial, and not an invented Rovela-Auth0 plugin.

Updated November 10, 2026
Auth0 Transactional Email API (2026): Warn About a New Device Sign-In from an Action with POST /emails

A new-device warning belongs in an Auth0 Action, not in a login page

When someone signs in from a device your app has not seen before, the account holder should hear it from you: “A new device signed in to your account,” with enough context — IP, user agent, time — to decide whether that was them. That send is transactional email. It is not a verification code, not a magic login link, not a password-reset message, and not a welcome email. Those tutorials already exist. It is also not a rewrite of the Clerk, Stytch, WorkOS, Descope, Cognito, Supabase, Better Auth, Lucia, SuperTokens, or Auth.js guides. This article is an Auth0 Action — typically post-login — that calls POST /emails itself.

Rovela’s Email API is built for that. There is no client library to install and no official Rovela-Auth0 plugin or marketplace tile in the public docs. Do not look for one in this guide. 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).

The Bearer key belongs in an Action secret (event.secrets), never in a single-page login form, a rule you paste into a public repository, or a mobile app bundle. The Action runs on Auth0’s server-side runtime; that is the only place this fetch should live.

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 an Action belongs on POST /emails.

An Auth0 post-login Action detects a new device, then posts JSON to the email API and receives a message id

What you need before the first Action send

The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch inside an Auth0 Action:

  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 Action. A full_access key can also read messages and events, and manage domains, templates, and webhooks. The full key is shown once. Store it as an Action secret, for example ROVELA_API_KEY.
  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 person first sees “a new device signed in” (HTML email API).

An Action secret and a small fetch helper

Create the secret in the Auth0 Action editor so it is available as event.secrets.ROVELA_API_KEY. Keep ROVELA_FROM there too, or hard-code only the verified from-address you already control — never the key. A leaked sending_access key can send mail as your domain.

The helper below is ordinary fetch inside the Action. Auth0 Actions run on a Node runtime that provides fetch; you do not need an invented official SDK.

// emails.js — used by the Action, secrets from event.secrets
class ApiError extends Error {
  constructor({ statusCode, name, message }) {
    super(message || `Rovela: HTTP ${statusCode}`);
    this.statusCode = statusCode;
    this.name = name || "ApiError";
  }
}

async function sendEmail(secrets, opts) {
  const apiKey = secrets.ROVELA_API_KEY;
  const from = secrets.ROVELA_FROM;
  if (!apiKey || !from) {
    throw new Error("Missing ROVELA_API_KEY or ROVELA_FROM Action secret");
  }

  const headers = {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  };
  if (opts.idempotencyKey) headers["Idempotency-Key"] = opts.idempotencyKey;

  const body = { from, to: opts.to, subject: opts.subject };
  if (opts.html) body.html = opts.html;
  if (opts.text) body.text = opts.text;
  if (opts.replyTo) body.reply_to = opts.replyTo;
  if (opts.tags) body.tags = opts.tags;

  const res = await fetch("https://api.rovela.dev/emails", {
    method: "POST",
    headers,
    body: JSON.stringify(body),
  });
  const payload = await res.json().catch(() => ({}));
  if (!res.ok) {
    throw new ApiError({
      statusCode: Number(payload.statusCode || res.status),
      name: payload.name,
      message: payload.message,
    });
  }
  return payload; // { object: "email", id }
}

exports.ApiError = ApiError;
exports.sendEmail = sendEmail;

The JSON body and headers are the same ones the Emails API documents. Keep this module in the Action’s server-side code, not in a spa that Auth0 redirects to after login.

If replies should reach a security desk rather than a no-reply address, set documented reply_to on the send (reply-to). Do not invent custom header names for this message; the Emails API allows a headers object, but this guide will not invent an allowlist or example header names beyond what the docs show. Tags such as purpose=new-device-signin are enough to find the message later in your own logs.

A post-login Action that warns about a new device

A new-device notice is easy to double-send: the login is retried, a silent renewal looks like a new session, or two Actions in the same flow both fire. Put your own detection in front of the send — for example, compare event.request.ip and event.request.user_agent to a fingerprint you already stored in app_metadata or in your own database — and give every alert a stable Idempotency-Key that includes the user id and that fingerprint. An Idempotency-Key may be up to 256 characters; a retry of the same request within 24 hours returns the original response instead of sending again (idempotency).

This article does not invent an Auth0 “new device” API, and it does not invent a Rovela devices API. Auth0 exposes request context such as IP and user agent on event.request; whether that combination is new is your product’s decision. The Action should not block the login just because mail is still queueing.

// post-login Action (server-side). Not a Rovela-Auth0 plugin.
const { ApiError, sendEmail } = require("./emails");

exports.onExecutePostLogin = async (event, api) => {
  const email = event.user && event.user.email;
  const userId = event.user && event.user.user_id;
  const ip = (event.request && event.request.ip) || "unknown";
  const userAgent = (event.request && event.request.user_agent) || "unknown";
  const signedInAt = new Date().toISOString();

  if (!email || !userId) {
    return; // nothing to notify
  }

  const fingerprint = `${ip}|${userAgent}`.slice(0, 180);
  const seen = ((event.user.app_metadata || {}).known_devices) || [];
  if (seen.includes(fingerprint)) {
    return; // already known; do not send
  }

  // Record the device in your own metadata or store. This is your data, not a Rovela field.
  const next = Array.from(new Set(seen.concat(fingerprint))).slice(-20);
  api.user.setAppMetadata("known_devices", next);

  try {
    await sendEmail(event.secrets, {
      to: email,
      subject: "A new device signed in to your account",
      html: `<p>A new device signed in to your account.</p>
<p>Time: ${signedInAt}</p>
<p>IP: ${ip}</p>
<p>Client: ${userAgent}</p>
<p>If this was not you, change your password and review active sessions.</p>`,
      text: `A new device signed in to your account.
Time: ${signedInAt}
IP: ${ip}
Client: ${userAgent}
If this was not you, change your password and review active sessions.`,
      tags: { purpose: "new-device-signin", user_id: userId },
      idempotencyKey: `new-device:${userId}:${fingerprint}`.slice(0, 256),
    });
  } catch (err) {
    if (err instanceof ApiError) {
      console.log("new-device email failed", err.statusCode, err.message);
      return;
    }
    throw err;
  }
};

fingerprint is your domain logic. If you already track devices in your own service, call that service from the Action and skip the app_metadata sketch. Do not send a verification code, a magic link, or a password-reset URL from this handler; those are different messages and different guides.

If you later need many personalized notices in one go — a security review that fans out to a tenant’s admins — use batch (POST /emails/batch, up to 100 messages, each processed independently). template and topic_id are rejected on batch rather than ignored; send those through POST /emails. See the batch example and the batch transactional email guide. Tags are documented as arbitrary labels and come back with the message (email API tags).

Errors you should handle in the helper

Every documented error uses the same envelope, so one ApiError covers them (Quick Start, Email API error handling):

{ "statusCode": 400, "name": "Bad Request", "message": "html or text body is required" }

The message says what was wrong. Surface it in the Action logs as-is.

  • 400 — a missing required field, a base64 attachment that does not decode, a from domain that does not belong to your organization, a template that does not exist, or more than 50 recipients on one message.
  • 401 — missing or invalid credential, or a sending_access key used to read, reschedule, or cancel a message.
  • 429 — rate limit exceeded. The first-email guide notes that the rate limit is per key, and that each message in a batch counts individually. The official batch example waits on Retry-After when that header is present (and falls back to one second if it is not). This article will not invent a requests-per-second number, because the public docs do not publish one. Retries of a failed HTTP call should reuse the same idempotency key (Email API retries, rate limits).

HTTP 200 on send is not delivery. If you need to look a message up later, GET /emails/:id and GET /emails/:id/events require a full_access key or a dashboard session — do not put that key in the same Action secret you use to send. Managing sending domains is a different API and a different key scope (Domains API, Email API authentication, sending domains API). A sending_access key used on a management endpoint such as GET /domains is documented as 403; that is not the same as a failed send.

The Action should not fail the login just because mail queued slowly. Record the new device, log the error, and let your webhook or a later retry (with the same idempotency key) finish the notice.

Delivery is asynchronous — do not poll from the Action

The Action should fire the send and return. Confirm delivery in the dashboard, with the Email delivery status API, or with a webhook. For production, prefer a webhook over polling GET /emails/:id from the post-login path. A login should not wait on inbox arrival.

A webhook endpoint in your own API reads the raw body, verifies x-resend-signature, and returns 2xx quickly. Verification is byte-exact HMAC-SHA256 over "<timestamp>.<raw body>" (webhook security). A 400 you return because a payload surprised you is a permanent loss; store anything you do not yet understand rather than rejecting it. Deduplicate on the event id. Managing webhook endpoints themselves is covered in the Email Webhooks API guide and the signature verification walkthrough.

When you need a message to go out later — a follow-up if the session still looks unfamiliar — use scheduled_at (scheduled email). POST /emails/:id/cancel can cancel a message that has not been sent yet; reading, rescheduling, and cancelling need a full_access key or a dashboard session. Public docs do not describe a reschedule request body, so this article will not invent one. Reusable layouts belong in the Templates API and the templates guide.

A verification-code Action is a different tutorial; a post-login Action posts a new-device warning with POST /emails

What not to do in an Auth0 Action

Do not invent a Rovela-Auth0 plugin, a marketplace integration, a dashboard click path that is not in the docs, or a special device object Rovela would have to provide. This integration is plain HTTP from your Action.

Do not call the Emails API from the login page, a mobile app, or any client Auth0 redirects to after a successful sign-in. The key would travel with that client. Keep it in event.secrets.

Do not turn this article into a verification-code, magic-link, password-reset, or welcome-email rewrite. Those messages have different content, different idempotency keys, and their own tutorials.

Do not point an SMTP client at Rovela mailbox SMTP and call that your Action mailer. Mailbox SMTP is for mail apps: a mailbox can send only as itself, and a single client address is limited to 30 messages a minute. That is the wrong default for app volume, which is the point of Email API vs SMTP relay as well.

Do not treat this guide as a broadcast or contacts tour. Public docs for contacts, topics, segments, and broadcasts are not used as a product walkthrough here. This helper is for the mail your Auth0 Action sends after a new device signs in.

Hosted mailboxes are a different product surface. People can read and send from them in a mail app. Your Action should not share a device credential with someone else’s Thunderbird profile.

If you send security mail on behalf of several tenants from one organization, restrict a key to a single domain so a leak cannot send as somebody else (Email API for multi-tenant SaaS). Nearby notification patterns live in the email notification API overview if you need a broader map, then come back here for the Auth0 shape.

If you later compare providers, the documented pages include Rovela vs Postmark, vs Resend, vs SendGrid, vs Mailgun, vs Brevo, and vs Amazon SES.

A compact Auth0 Action checklist

  • Verify the sending domain before you set from. An unverified domain is a 400, not a silent drop.
  • Store ROVELA credentials as Action secrets and read them from event.secrets. Never put the key in a login page.
  • Prefer a sending_access key in the production Action; keep full_access for tooling that reads events or manages webhooks.
  • Decide in your own logic whether the device is new, send both html and text when you can, and set an Idempotency-Key derived from the user id and device fingerprint.
  • Do not fail the login because mail is still queueing. Watch delivery with a webhook, not a loop in the Action.
  • If you need a first request in curl, use the transactional email API overview, the curl sending guide, or the HTTP email API explainer — then come back to this helper for the Auth0 Action shape.