← Back to blog

Netlify Functions Transactional Email API (2026): Send App Mail from an On-Demand Function with POST /emails

Send transactional email from an on-demand Netlify Function (HTTP, not a cron job) with Rovela’s HTTP API: environment variables for the Bearer key, a support-ticket notice after a form post, and Idempotency-Key.

Updated November 10, 2026
Netlify Functions Transactional Email API (2026): Send App Mail from an On-Demand Function with POST /emails

A Netlify Function is already on-demand; transactional email belongs there

A Netlify Function already runs in a short-lived environment you control: site environment variables hold secrets, the handler receives an HTTP request after a form or an app event, and nothing from that process is shipped to the static site. Transactional email — “we opened a support ticket from your form,” a booking notice, a security alert — is that kind of work. The natural way to send it is one HTTPS POST with a Bearer key, not a mailbox SMTP session or a form-forwarding hack.

Rovela’s Email API is built for that. There is no client library to install and no official Netlify plugin 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 cron job and it is not a scheduled-function tour. Recurring windows already live in the Netlify Scheduled Functions email guide. This article is an on-demand HTTP function: a contact form posts to your function, your app opens a support ticket, and the function sends a confirmation with an Idempotency-Key. The trigger is “this form was submitted,” not “it is 9:00 again.”

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 Netlify Function belongs on POST /emails.

An on-demand Netlify Function posts JSON to the email API after a contact form opens a support ticket and receives a message id

What you need before the first Netlify Function send

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

  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).

Site environment variables and a small emails helper

Keep the key in the site’s environment (the Netlify UI or your deploy config), marked so it is available to functions and not inlined into the frontend build. Never prefix it as a public browser variable, never commit it, and never return it from the handler. A leaked sending_access key can send mail as your domain.

A current Node.js function runtime already has fetch. You do not need a second HTTP client just to send mail. The JSON body and headers are the same ones the Emails API documents.

// netlify/functions/lib/emails.mjs
export class ApiError extends Error {
  constructor({ statusCode, name, message }) {
    super(message || `Rovela: HTTP ${statusCode}`)
    this.statusCode = statusCode
    this.name = name || 'ApiError'
  }
}

export async function sendEmail({ to, subject, html, text, replyTo, tags, idempotencyKey }) {
  const apiKey = process.env.ROVELA_API_KEY
  const from = process.env.ROVELA_FROM
  if (!apiKey || !from) {
    throw new Error('Missing ROVELA_API_KEY or ROVELA_FROM')
  }

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

  const body = { 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('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
}

Set ROVELA_API_KEY and ROVELA_FROM on the site (for example Acme <hello@mail.example.com>). Prefer a sending_access key in the production function. Keep full_access out of this handler — you do not need it to queue a ticket confirmation.

A function that sends after a support ticket is opened

A form that opens a support ticket is a good everyday example because it is not a login code and it is easy to double-send: the browser retries, a user double-clicks submit, a preview deploy hits the same ticket id. Give every ticket 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.

The function below is a plain HTTP handler. It is not a scheduled function, it has no cron expression, and it should not be registered as one.

// netlify/functions/ticket-opened.mjs
import { sendEmail, ApiError } from './lib/emails.mjs'

export async function handler(event) {
  if (event.httpMethod !== 'POST') {
    return { statusCode: 405, body: 'Method Not Allowed' }
  }

  const body = JSON.parse(event.body || '{}')
  const ticketId = String(body.ticketId || '')
  if (!ticketId) {
    return { statusCode: 400, body: JSON.stringify({ error: 'Missing ticket' }) }
  }

  const ticket = await loadOpenedTicket(ticketId)
  const ticketUrl = signedTicketUrl(ticket)

  try {
    const result = await sendEmail({
      to: ticket.requesterEmail,
      subject: 'We opened a support ticket from your form',
      html: `<p>Ticket ${ticket.number} is open.</p><p><a href="${ticketUrl}">View ticket</a></p>`,
      text: `Ticket ${ticket.number} is open. View it here: ${ticketUrl}`,
      replyTo: ticket.supportInbox,
      tags: { purpose: 'ticket-opened', ticket_id: ticketId },
      idempotencyKey: `ticket-opened:${ticketId}`,
    })
    return { statusCode: 200, body: JSON.stringify({ ok: true, emailId: result.id }) }
  } catch (err) {
    if (err instanceof ApiError) {
      return {
        statusCode: 502,
        body: JSON.stringify({ error: err.message, statusCode: err.statusCode }),
      }
    }
    throw err
  }
}

Your static form — or the page that handles the submission — should POST JSON to /.netlify/functions/ticket-opened only after you have created the ticket in your own store and only if that path is protected the way the rest of your app is protected (a hidden token, a session, or a server-side check). The Emails API is called from your function, not from the browser. The form must never call api.rovela.dev with a key the client can see.

This is also not “use a built-in form notification as your product mailer.” Built-in form forwarding is a convenience for site owners. A ticket confirmation to the person who submitted the form is application mail, and it belongs on POST /emails with an idempotency key you control.

loadOpenedTicket and signedTicketUrl are your domain code. This article does not invent a Rovela tickets endpoint — Rovela accepts the message you already decided to send.

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 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 — without logging the API key.

  • 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 function that sends every ticket confirmation. 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 function

The function 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 can be a second on-demand function 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.

Mailbox SMTP or a form-forwarding hack is send-as-self and capped; Netlify Function app volume belongs on POST /emails

What not to do in a Netlify Functions 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 a public repository, in a frontend bundle, or in a NETLIFY variable that is exposed to the browser build. Call the API from the function. Authentication is explicit: a browser bundle is readable by anyone who has it.

Do not treat this guide as a replacement for the scheduled-functions article. A cron window is a different job. This function is for mail your product sends because a form just opened a ticket — a confirmation, not a daily digest and not a one-time passcode.

Hosted mailboxes are a different product surface. People can read and send from them in a mail app. Your function should not share a device credential with someone else’s Apple Mail 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 compare providers, the documented pages include Rovela vs Resend, vs SendGrid, vs Postmark, vs Mailgun, vs Brevo, and vs Amazon SES.

A compact Netlify Functions checklist

  • Verify the sending domain before you set from. An unverified domain is a 400, not a silent drop.
  • Keep ROVELA credentials in site env available to functions, not in the frontend build.
  • Prefer a sending_access key in the production ticket function; 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 function. 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 function for the Netlify shape.