← Back to blog

Nuxt Transactional Email API (2026): Send App Mail from a Nitro Route with POST /emails

Send transactional email from Nuxt 3 with Rovela’s HTTP API: a Nitro server utility, private runtimeConfig for the Bearer key, a server/api route, and Idempotency-Key. Not an OTP tutorial.

Updated November 10, 2026
Nuxt Transactional Email API (2026): Send App Mail from a Nitro Route with POST /emails

Nuxt already has a server; transactional email belongs in Nitro

A Nuxt 3 app already splits work in two: Vue components render the page, and Nitro — server/api routes, server/utils, server plugins — does anything that needs a secret. Transactional email — “your weekly usage report is ready,” a seat that was reserved, a comment mention, a security notice — is that second kind of work. The natural way to send it is one HTTPS POST with a Bearer key, not an SMTP session hidden in a Nitro plugin.

Rovela’s Email API is built for that. There is no official SDK and no Nuxt module you have to pin. 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 is not a redo of a one-time passcode tutorial. If you need a signup or login code, start from the existing Nuxt OTP guide. This article is everyday app mail: a Nitro utility, private runtime config for the key, a server/api route that sends after a report job finishes, an Idempotency-Key on anything a retry might repeat, and documented error handling around the {statusCode, name, message} envelope.

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 Nuxt server belongs on POST /emails.

A Nuxt Nitro server/api route calls a server-only emails utility that posts JSON to the email API and receives a message id

What you need before the first Nuxt send

The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch inside a Nitro handler:

  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. 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 production. 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 "Acme <hello@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 (HTML email API).

A Nitro emails utility and private runtime config

Keep the key on the server. Never put it in runtimeConfig.public, never prefix the env var with NUXT_PUBLIC_, and never import the utility from a Vue component, a composable that runs in the browser, or a plugin without an explicit server-only guard. A leaked sending_access key can send mail as your domain.

In Nuxt 3, private values belong in runtimeConfig (the root object, not public) and are overridden by NUXT_ environment variables. useRuntimeConfig() inside server/ is the right place to read them.

// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    rovelaApiKey: '',
    rovelaFrom: '',
    public: {}
  }
})
# .env (server only; never NUXT_PUBLIC_*)
NUXT_ROVELA_API_KEY=re_your_sending_key
NUXT_ROVELA_FROM=Acme <hello@mail.example.com>

The helper below uses the platform fetch already available in Nitro, so the module does not need a second HTTP client just to send mail. The JSON body and headers are the same ones the Emails API documents.

// server/utils/emails.ts
export class ApiError extends Error {
  statusCode: number
  name: string
  constructor({ statusCode, name, message }: { statusCode: number; name?: string; message?: string }) {
    super(message || `Rovela: HTTP ${statusCode}`)
    this.statusCode = statusCode
    this.name = name || 'ApiError'
  }
}

export async function sendEmail({
  to,
  subject,
  html,
  text,
  replyTo,
  tags,
  idempotencyKey
}: {
  to: string | string[]
  subject: string
  html?: string
  text?: string
  replyTo?: string | string[]
  tags?: Record<string, string> | Array<{ name: string; value: string }>
  idempotencyKey?: string
}) {
  const config = useRuntimeConfig()
  const headers: Record<string, string> = {
    Authorization: `Bearer ${config.rovelaApiKey}`,
    'Content-Type': 'application/json'
  }
  if (idempotencyKey) headers['Idempotency-Key'] = idempotencyKey

  const body: Record<string, unknown> = { from: config.rovelaFrom, to, subject }
  if (html) body.html = html
  if (text) body.text = text
  if (replyTo) body.reply_to = replyTo
  if (tags) body.tags = 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: payload.statusCode || res.status,
      name: payload.name,
      message: payload.message
    })
  }
  return payload // { object: 'email', id: '...' }
}

A server/api route that sends after a report is ready

The weekly usage report is a good everyday example because it is not a login code and it is easy to double-send: a cron job retries, a queue redelivers, a developer hits the route twice. Put the send behind an internal Nitro route, and give every report a stable Idempotency-Key. 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.

// server/api/reports/ready.post.ts
export default defineEventHandler(async (event) => {
  const body = await readBody(event)
  const reportId = String(body?.reportId || '')
  if (!reportId) {
    throw createError({ statusCode: 400, statusMessage: 'Missing report' })
  }

  const report = await loadReadyReport(reportId)
  const downloadUrl = signedReportUrl(report)

  try {
    const result = await sendEmail({
      to: report.ownerEmail,
      subject: 'Your weekly usage report is ready',
      html: `<p>Your usage report can be downloaded here:</p><p><a href="${downloadUrl}">Download report</a></p>`,
      text: `Your usage report can be downloaded: ${downloadUrl}`,
      tags: { purpose: 'usage-report', report_id: reportId },
      idempotencyKey: `usage-report:${reportId}`
    })
    return { ok: true, emailId: result.id }
  } catch (err) {
    if (err instanceof ApiError) {
      throw createError({
        statusCode: 502,
        statusMessage: err.message,
        data: { statusCode: err.statusCode }
      })
    }
    throw err
  }
})

Keep that route off the public internet, or authenticate it yourself — a signed header from your worker, a private network, or a Nitro middleware check. The Emails API is called from your server, not from the browser. A Vue button should POST to your own /api/reports/ready only if that path already requires a session; it must never call api.rovela.dev with a key the client can see.

If you later need many personalized messages in one go, 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.

Errors you should handle in the utility

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 your own 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.

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 utility you call from every report job. 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.

Delivery is asynchronous — do not poll from the Nitro handler

The route should record the message id 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 request path.

A webhook endpoint in Nuxt is a POST server/api route that 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.

When you need a message to go out later, use scheduled_at (scheduled email). When you need many sends in one request, use batch transactional email. Reusable layouts belong in the Templates API and the templates guide.

Nodemailer or mailbox SMTP in a Nitro plugin is send-as-self and capped; Nuxt app volume belongs on POST /emails

What not to do in a Nuxt codebase

Do not point Nodemailer, or any other SMTP client, at Rovela mailbox SMTP and call that your application 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 put a Rovela key in runtimeConfig.public, a NUXT_PUBLIC_ variable, or a composable imported by a Vue component. Call the API from server/utils, server/api, or another Nitro-only module. Authentication is explicit: a browser bundle is readable by anyone who has it.

Do not treat this guide as a replacement for the OTP article. Code generation, expiry, and resend limits are already covered there. This utility is for the mail your product sends after a user already has a session — reports, invoices, notices.

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

If you send on behalf of several customers from one organization, restrict a key to a single domain so a leak cannot send as somebody else (Email API for multi-tenant SaaS). Retries of a failed HTTP call should reuse the same idempotency key (Email API retries).

The same utility works under Nuxt’s Node preset or a serverless / edge Nitro preset, because it is just fetch and private runtime config. What changes is where you trigger it. A server/api route is the right default when a worker in your own network says the report finished. A Nitro scheduled task can call the same helper. In both cases the emails module stays under server/, and the client bundle must never receive the key. If you also use server/plugins, keep them for logging and request hooks — they are a poor place to open an SMTP connection, and an easy place to import a server module into a path that later ships to the browser.

This is also not a SvelteKit or Next.js rewrite. SvelteKit’s everyday-send shape lives in the SvelteKit transactional email guide; Next.js App Router already has send email in Next.js. Nuxt’s difference is Nitro: useRuntimeConfig(), server/api, and a Vue UI that must stay away from the key.

A compact Nuxt checklist

  • Verify the sending domain before you set from. An unverified domain is a 400, not a silent drop.
  • Keep ROVELA credentials in private runtimeConfig and import them only from server/ modules.
  • Prefer a sending_access key in production report jobs; keep full_access for tooling that reads events or manages webhooks.
  • Send both html and text when you can, and set an Idempotency-Key on any path a retry can hit twice.
  • Record the message id and return from the Nitro handler. Watch delivery with a webhook, not a loop on the request path.
  • 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 utility for the Nuxt shape.