Google Cloud Functions Transactional Email API (2026): Send a Video-Ready Notice with POST /emails
Send transactional email from an on-demand Google Cloud Function (HTTP or event, not Cloud Scheduler) with Rovela’s HTTP API: environment variables for the Bearer key, native fetch, and Idempotency-Key. Distinct from the Cloud Scheduler, Lambda, and Netlify guides.
Cloud Functions already run off the request path; transactional email belongs in the handler
A Google Cloud Function is a small server you do not have to keep running yourself. The interesting case for transactional email is an on-demand function: an HTTP call or an event from your own pipeline, not a timer. When a video finishes transcoding, something should tell the owner “your video is ready to watch.” The natural way to send that is one HTTPS POST with a Bearer key from the function, not a Cloud Scheduler job that wakes up every minute to look for work, and not an SMTP session from a long-lived VM.
Rovela’s Email API is built for that. There is no client library to install and no official Cloud Functions wrapper 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 rewrite of the GCP Cloud Scheduler email guide. That article is a cron-shaped send. This one is an on-demand HTTP (or event) function that fires because a video became ready. It is also not a rewrite of the AWS Lambda transactional email or Netlify Functions transactional email guides — those are different runtimes, different secret stores, and different everyday stories (a payment receipt and a support-ticket notice). Here the story is “your video is ready to watch.”
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 Cloud Function belongs on POST /emails.
What you need before the first Cloud Function send
The first-email guide and the Quick Start are the same five steps, whether your caller is curl or fetch inside a Cloud Function:
- 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 "Studio <video@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).
Environment variables and a small send helper
Keep the key out of the source tree. In Cloud Functions, private values belong in environment variables or Secret Manager, injected into the function at deploy time. Never put a Rovela key in a client app, a public Cloud Storage object, or a repository. A leaked sending_access key can send mail as your domain.
# set at deploy time; never commit the live key
ROVELA_API_KEY=re_your_sending_key
ROVELA_FROM=Studio <video@mail.example.com>
The helper below uses the platform fetch already available in a current Node runtime, so the function does not need a second HTTP client just to send mail. The JSON body and headers are the same ones the Emails API documents.
// emails.js
function requireEnv(name) {
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 {
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 headers = {
Authorization: `Bearer ${ROVELA_API_KEY}`,
'Content-Type': 'application/json',
}
if (idempotencyKey) {
headers['Idempotency-Key'] = idempotencyKey
}
const body = { from: ROVELA_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
}
An on-demand HTTP function after a video is ready
A video that just finished transcoding is a good everyday example because it is not a login code and it is easy to double-send: the transcoding pipeline retries, a pub/sub message is redelivered, an operator replays the HTTP call. Put the send behind the function, and give every video 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.
This is a 2nd gen HTTP function with the Functions Framework. Your transcoding worker — or an Eventarc trigger you already have — calls it when the output object exists. It is not a Cloud Scheduler job, and it does not wake up on a cron expression to look for ready videos.
// index.js
import functions from '@google-cloud/functions-framework'
import { ApiError, sendEmail } from './emails.js'
functions.http('videoReady', async (req, res) => {
if (req.method !== 'POST') {
res.status(405).json({ error: 'POST only' })
return
}
const video = await markVideoReady(req.body || {})
if (!video?.id || !video.ownerEmail || !video.watchUrl) {
res.status(400).json({ error: 'Missing video payload' })
return
}
try {
const result = await sendEmail({
to: video.ownerEmail,
subject: 'Your video is ready to watch',
html: `<p>${video.title} is ready.</p><p><a href="${video.watchUrl}">Watch video</a></p>`,
text: `${video.title} is ready to watch: ${video.watchUrl}`,
tags: { purpose: 'video-ready', video_id: video.id },
idempotencyKey: `video-ready:${video.id}`,
})
res.status(200).json({ ok: true, emailId: result.id })
} catch (err) {
if (err instanceof ApiError) {
res.status(502).json({ error: err.message, statusCode: err.statusCode })
return
}
throw err
}
})
Protect that HTTP function — require IAM authentication, a shared secret header from your worker, or both. The Emails API is called from your Cloud Function, not from a browser. A “Notify owner” button in a dashboard should POST to your function only if that path is already authenticated; it must never call api.rovela.dev with a key the client can see.
markVideoReady is your domain code. This article does not invent a Rovela video endpoint — Rovela accepts the message you already decided to send.
If your pipeline is event-shaped instead of HTTP-shaped, the same helper belongs in a CloudEvent function. The trigger changes; the send does not. What you should not do is move this work onto Cloud Scheduler just because the function platform also supports a schedule. Scheduled sends are a different article.
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 function
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 function you call from every transcoding event. 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. Cloud Functions have a finite request timeout; a delivery loop does not belong there.
A webhook endpoint can be a second HTTP 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.
What not to do in a Cloud Function
Do not turn this into a Cloud Scheduler article. If you need a cron-shaped send on Google Cloud, start from GCP Cloud Scheduler email. This function exists because a video became ready, not because a clock ticked.
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 asset, a client-side Firebase config, or a repository. 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 an OTP article, and do not treat it as a Lambda or Netlify rewrite. The AWS Lambda transactional email guide sends a payment receipt from Lambda. The Netlify Functions transactional email guide opens a support ticket from a form post. This one notifies a creator that a video is ready, from an on-demand Cloud Function.
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 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 compare providers, the documented pages include Rovela vs Resend, vs SendGrid, vs Postmark, vs Mailgun, vs Brevo, and vs Amazon SES.
A compact Cloud Functions checklist
- Verify the sending domain before you set
from. An unverified domain is a 400, not a silent drop. - Keep
ROVELAcredentials in environment variables or Secret Manager, never in the repo or a client app. - Prefer a
sending_accesskey in the production function; 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 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 Cloud Functions shape.