How to send email from a serverless function

Transactional email from serverless — Vercel, Cloudflare Workers, Supabase Edge, Lambda — one HTTPS call, no SMTP.

Send transactional email from a serverless function with an HTTPS email API. Serverless platforms rarely make outbound SMTP pleasant (blocked ports, cold starts, timeouts). A single fetch (or equivalent) to Notify fits the model.

Pattern: store NOTIFY_API_KEY as a function secret → POST https://notify.cx/api/email/send with x-api-key → JSON { to, from, subject, message }.

Prerequisites

  • API key
  • Verified domain for production custom from
  • A serverless runtime that can call HTTPS (fetch, requests, curl, etc.)

Generic handler (TypeScript)

Works on Vercel Route Handlers, Cloudflare Workers, Supabase Edge Functions, and similar fetch-capable runtimes:

export async function sendEmail(
  apiKey: string,
  input: { to: string; subject: string; message: string; from?: string }
) {
  const response = await fetch('https://notify.cx/api/email/send', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': apiKey
    },
    body: JSON.stringify({
      from: input.from ?? 'noreply@your-verified-domain.com',
      to: input.to,
      subject: input.subject,
      message: input.message
    })
  });

  if (!response.ok) {
    throw new Error(await response.text());
  }

  return response.json();
}

Keep the key in the platform secret store — never in the client bundle or a public env var.


Platform map

PlatformWhere to put the keyDeep dive
VercelProject env vars (not NEXT_PUBLIC_*)Vercel guide
Next.js on VercelSame + Route Handler / Server ActionNext.js, Server Action recipe
Cloudflare WorkersWorker secretWorkers guide, Edge recipe
Supabase Edge Functionssupabase secrets setSupabase guide
AWS LambdaSecrets Manager / env (IAM as needed)Same HTTPS body; no Notify SDK required
Cron / GitHub ActionsActions secretsCron recipe

Why this beats SMTP in serverless

  • No long SMTP handshake against short function timeouts
  • HTTP status codes and JSON errors
  • Same helper across Edge, Workers, and Node serverless
  • Provider logs and webhooks without running a relay

See SMTP vs email APIs.


Where to next?