AnalogJS Transactional Email API (2026): Approve an Expense Report from a Server Route with POST /emails
Send transactional email from AnalogJS with Rovela’s HTTP API: a Nitro/h3 server route, environment variables for the Bearer key, an expense-approved notice, and Idempotency-Key. Not a browser HttpClient post and not an OTP tutorial.
AnalogJS already has a server; transactional email does not belong in HttpClient
AnalogJS is an Angular meta-framework with a Nitro server in the same repo. Components, pipes, and HttpClient run in the browser; files under src/server/routes run on the server. Transactional email — “your expense report was approved,” a payout that just cleared, a policy notice — is that second kind of work. The natural way to send it is one HTTPS POST with a Bearer key from a server route, not an Angular service that the browser can read.
Rovela’s Email API is built for that. There is no client library to install and no official AnalogJS mailer 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, and it is not a generic Angular client walkthrough. A component that calls api.rovela.dev with a key in environment.ts is a leak, not an integration. This article is everyday app mail in AnalogJS: a server-only helper, a Nitro/h3 route that sends after an expense report is approved, environment variables for the key, an Idempotency-Key on anything a retry might repeat, and documented error handling around the {statusCode, name, message} envelope. It is also not a rewrite of the NestJS transactional email guide or the Nuxt transactional email guide — NestJS uses modules and injectable providers; Nuxt shares Nitro with Analog but is a Vue app. Analog’s difference is Angular on the client and a file-based server route on the edge of your API.
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 AnalogJS server route belongs on POST /emails.
What you need before the first AnalogJS send
The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch inside a Nitro route:
- 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. 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 production. 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 "Finance <expenses@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 server-only helper and environment variables
Keep the key on the server. Never put it in src/environments/environment.ts, never expose it through an Analog API route that returns configuration to the browser, and never import the helper from a standalone component. A leaked sending_access key can send mail as your domain.
Private values belong in the server environment Nitro already reads. A missing key should fail when the route module loads, not halfway through an approval.
// src/server/emails.ts
function requireEnv(name: string): string {
const value = process.env[name]
if (!value) {
throw new Error(`Missing required environment variable: ${name}`)
}
return value
}
const ROVELA_API_KEY = requireEnv('ROVELA_API_KEY')
const ROVELA_FROM = requireEnv('ROVELA_FROM')
export class ApiError extends Error {
statusCode: number
override 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(input: {
to: string | string[]
subject: string
html?: string
text?: string
replyTo?: string | string[]
tags?: Record<string, string> | Array<{ name: string; value: string }>
idempotencyKey?: string
}) {
const headers: Record<string, string> = {
Authorization: `Bearer ${ROVELA_API_KEY}`,
'Content-Type': 'application/json',
}
if (input.idempotencyKey) {
headers['Idempotency-Key'] = input.idempotencyKey
}
const body: Record<string, unknown> = {
from: ROVELA_FROM,
to: input.to,
subject: input.subject,
}
if (input.html) body.html = input.html
if (input.text) body.text = input.text
if (input.replyTo) body.reply_to = input.replyTo
if (input.tags) body.tags = input.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 as { object: string; id: string }
}
# .env (server only; never commit the live key)
ROVELA_API_KEY=re_your_sending_key
ROVELA_FROM=Finance <expenses@mail.example.com>
The helper uses the platform fetch already available in the Node runtime Nitro runs on, 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.
A server route that sends after an expense report is approved
An expense report that just cleared review is a good everyday example because it is not a login code and it is easy to double-send: a reviewer clicks twice, a workflow engine retries, a job redelivers. Put the send behind a file-based Analog server 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.
AnalogJS server routes live under src/server/routes and use defineEventHandler from h3. A file named src/server/routes/api/expenses/[id]/approve.post.ts becomes POST /api/expenses/:id/approve.
// src/server/routes/api/expenses/[id]/approve.post.ts
import { createError, defineEventHandler, getRouterParam } from 'h3'
import { ApiError, sendEmail } from '../../../../emails'
export default defineEventHandler(async (event) => {
const reportId = getRouterParam(event, 'id') || ''
if (!reportId) {
throw createError({ statusCode: 400, statusMessage: 'Missing expense report' })
}
const report = await approveExpenseReport(event, reportId)
const total = formatMoney(report.total, report.currency)
try {
const result = await sendEmail({
to: report.ownerEmail,
subject: 'Your expense report was approved',
html: `<p>Expense report ${report.number} for ${total} was approved.</p><p>The reimbursement is on its way.</p>`,
text: `Expense report ${report.number} for ${total} was approved. The reimbursement is on its way.`,
tags: { purpose: 'expense-approved', report_id: report.id },
idempotencyKey: `expense-approved:${report.id}`,
})
return { ok: true, emailId: result.id, number: report.number }
} 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 session guard, a role check on the reviewer, or a signed header from your workflow worker. The Emails API is called from your AnalogJS server, not from the browser. An “Approve” button in an Angular component should POST to your own /api/expenses/:id/approve only if that path already requires a session; it must never call api.rovela.dev with a key HttpClient can see.
approveExpenseReport and formatMoney are your domain code. This article does not invent a Rovela expenses endpoint — Rovela accepts the message you already decided to send.
If you later need many personalized messages in one go — a weekly batch of approved reports — 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 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 your own logs as-is.
400— a missing required field, a base64 attachment that does not decode, afromdomain that does not belong to your organization, atemplatethat does not exist, or more than 50 recipients on one message.401— missing or invalid credential, or asending_accesskey 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 onRetry-Afterwhen 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 helper you call from every approval route. 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 route
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 AnalogJS is another POST file under src/server/routes 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). 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. When you need many sends in one request, use batch transactional email. Reusable layouts belong in the Templates API and the templates guide.
What not to do in an AnalogJS codebase
Do not put the Rovela key in an Angular environment file, a provideAppInitializer, or any service that HttpClient can import. Authentication is explicit: a browser bundle is readable by anyone who has it. The approval button talks to your Analog route; the Analog route talks to Rovela.
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 treat this guide as a replacement for an OTP article. Code generation, expiry, and resend limits belong in a verification-code design, not in an expense-approved route. This helper is for the mail your product sends after someone already filed a report — approvals, rejections, reimbursement notices.
Do not assume this is a NestJS or Nuxt rewrite. If you are on NestJS, start from the NestJS transactional email guide. If you are on Nuxt, use the Nuxt transactional email guide. AnalogJS’s difference is the Angular client plus a file-based Nitro route. Nearby Node HTTP options also live in sending email in Node.js and how to send email in Node.js.
Hosted mailboxes are a different product surface. People can read and send from them in a mail app. Your AnalogJS process should not share a device credential with someone else’s Thunderbird profile.
If you send on behalf of several companies 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).
If you later compare providers, the documented pages include Rovela vs Resend, vs SendGrid, vs Postmark, vs Mailgun, vs Brevo, and vs Amazon SES.
A compact AnalogJS checklist
- Verify the sending domain before you set
from. An unverified domain is a 400, not a silent drop. - Keep
ROVELAcredentials in server environment variables and import them only fromsrc/servermodules. - Prefer a
sending_accesskey in production approval routes; keepfull_accessfor tooling that reads events or manages webhooks. - Send both
htmlandtextwhen you can, and set anIdempotency-Keyon any path a retry can hit twice. - Record the message
idand return from the route. 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 route for the AnalogJS shape.