Deno Transactional Email API (2026): Send App Mail with Native fetch and POST /emails
Send transactional email from Deno with Rovela’s HTTP API: native fetch, Deno.env, Deno.serve, permission flags, and Idempotency-Key. Not an OTP tutorial and not a Node or Bun tour.
Deno already has fetch and a server; transactional email is one POST
Deno ships the pieces a mailer actually needs: native fetch, Deno.env, and Deno.serve. Transactional email — “your backup completed,” a mention notice, a report that is ready — still needs a secret, and the natural way to send it is one HTTPS POST with a Bearer key, not an SMTP session opened from the same process that just finished writing a backup file.
Rovela’s Email API is built for that. There is no official SDK and no Deno module you have to pin from a third-party registry just to send mail. 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 Node or Bun language tour. If you need a signup or login code, start from the existing Deno OTP guide. Everyday send on Bun is already covered in Bun transactional email. This article is everyday app mail on the Deno runtime: a module that uses native fetch, Deno.env for the key, a Deno.serve handler that sends after a backup finishes, the --allow-net and --allow-env permission flags, 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 Deno process belongs on POST /emails.
What you need before the first Deno send
The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch inside a Deno handler:
- 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 "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 Deno module, environment access, and permissions
Keep the key in the environment and read it with Deno.env.get. Do not hard-code it in a module that might be published or checked into a public repository. A leaked sending_access key can send mail as your domain.
Deno will not talk to the network or read environment variables unless you allow it. Grant only what the mailer needs, for example:
deno run --allow-net=api.rovela.dev --allow-env=ROVELA_API_KEY,ROVELA_FROM main.ts
You can express the same flags in deno.json if you prefer a task, but the idea does not change: the process may reach api.rovela.dev, and it may read those two variables. It does not need blanket --allow-all to send a message.
The helper below uses native fetch. The JSON body and headers are the same ones the Emails API documents.
// emails.ts
const BASE_URL = "https://api.rovela.dev";
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({
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 apiKey = Deno.env.get("ROVELA_API_KEY");
const from = Deno.env.get("ROVELA_FROM");
if (!apiKey || !from) {
throw new ApiError({
statusCode: 500,
name: "ConfigError",
message: "Missing ROVELA_API_KEY or ROVELA_FROM",
});
}
const headers: Record<string, string> = {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
};
if (idempotencyKey) headers["Idempotency-Key"] = idempotencyKey;
const body: Record<string, unknown> = { from, 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(`${BASE_URL}/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: "..." }
}
The 500 / ConfigError path is your process failing closed when it was started without a key or without --allow-env. It is not a status the Emails API documents for a send.
A Deno.serve handler that sends after a backup completes
A backup-completed notice is a good everyday example because backup jobs retry: a cron fires twice, a lock is lost, an operator reruns the task. Put the send behind an internal Deno.serve route, and give every backup 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.
// main.ts
import { ApiError, sendEmail } from "./emails.ts";
Deno.serve({ port: 8000 }, async (req) => {
const url = new URL(req.url);
if (req.method !== "POST" || url.pathname !== "/internal/backups/completed") {
return new Response("Not found", { status: 404 });
}
const body = await req.json().catch(() => ({}));
const backupId = String(body.backupId || "");
if (!backupId) {
return Response.json({ message: "Missing backup" }, { status: 400 });
}
const backup = await loadCompletedBackup(backupId);
const downloadUrl = signedBackupUrl(backup);
try {
const result = await sendEmail({
to: backup.ownerEmail,
subject: "Your backup completed",
html: `<p>Your backup finished successfully.</p><p><a href="${downloadUrl}">Download backup</a></p>`,
text: `Your backup finished successfully. Download it: ${downloadUrl}`,
tags: { purpose: "backup-completed", backup_id: backupId },
idempotencyKey: `backup-completed:${backupId}`,
});
return Response.json({ ok: true, emailId: result.id });
} catch (err) {
if (err instanceof ApiError) {
return Response.json(
{ message: err.message, statusCode: err.statusCode },
{ status: 502 },
);
}
throw err;
}
});
Keep that route off the public internet, or authenticate it yourself. The Emails API is called from your Deno process, not from the browser. If the backup job itself runs in the same process, you can also call sendEmail directly after the file is written — the HTTP handler is just a convenient boundary when another job on your network finishes the work.
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 module
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 module you call from every backup 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 handler
The handler 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 Deno is another Deno.serve route (or a pathname on the same server) 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.
What not to do in a Deno codebase
Do not point an 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 start the process with --allow-all just to send mail, and do not print Deno.env.toObject() into logs or a debug route. Authentication is explicit: a leaked key can send as your domain.
Do not treat this guide as a replacement for the OTP article, or as a rewrite of the Bun tour. Code generation and resend limits are already covered in the OTP guide. This module is for the mail your product sends after a job already finished — backups, invoices, notices.
Hosted mailboxes are a different product surface. People can read and send from them in a mail app. Your Deno process 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). If you later wrap these routes in Hono on Deno, the Hono transactional email guide covers the framework shape; the Deno-specific part remains Deno.env and the permission flags.
The same module works whether Deno.serve is the whole app or a small internal listener next to a CLI job, because it is just fetch and environment variables. What changes is where you trigger it.
A compact Deno checklist
- Verify the sending domain before you set
from. An unverified domain is a 400, not a silent drop. - Keep
ROVELA_API_KEYin the environment, read it withDeno.env.get, and grant only--allow-envand--allow-netfor this path. - Prefer a
sending_accesskey in production backup jobs; 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 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 module for the Deno shape.