Node.js
Option 1: Resend SDK (drop-in)
Section titled “Option 1: Resend SDK (drop-in)”npm install resendimport { Resend } from "resend";
const resend = new Resend(process.env.AMDY_API_KEY, { baseUrl: "https://mail.3ava.com/api",});
await resend.emails.send({ subject: "Hello", html: "<p>Hi.</p>",});Option 2: fetch (zero dependencies, Node 18+)
Section titled “Option 2: fetch (zero dependencies, Node 18+)”async function sendEmail(payload) { const res = await fetch("https://mail.3ava.com/api/emails", { method: "POST", headers: { Authorization: `Bearer ${process.env.AMDY_API_KEY}`, "Content-Type": "application/json", }, body: JSON.stringify(payload), }); if (!res.ok) { throw new Error(`3AVA Mail error: ${res.status} ${await res.text()}`); } return res.json();}
const result = await sendEmail({ subject: "Hello", html: "<p>Hi.</p>",});console.log(result.id);TypeScript types
Section titled “TypeScript types”If you’re using the Resend SDK, types are bundled. If you’re rolling your own, the minimum email shape:
interface AmdyEmail { from: string; to: string | string[]; subject: string; html?: string; text?: string; cc?: string | string[]; bcc?: string | string[]; reply_to?: string; headers?: Record<string, string>; attachments?: Array<{ filename: string; content: string; // base64 content_type?: string; content_id?: string; }>; tags?: Array<{ name: string; value: string }>; scheduled_at?: string; // ISO 8601}
interface AmdyEmailResponse { id: string; status: "queued" | "sent" | "delivered" | "bounced" | "failed" | "suppressed"; created_at: string;}Idempotency
Section titled “Idempotency”await fetch("https://mail.3ava.com/api/emails", { method: "POST", headers: { Authorization: `Bearer ${process.env.AMDY_API_KEY}`, "Idempotency-Key": `order-${orderId}-receipt`, "Content-Type": "application/json", }, body: JSON.stringify({...}),});Inside Next.js
Section titled “Inside Next.js”A typical pattern — a server action that sends a magic link:
"use server";
import { Resend } from "resend";
const resend = new Resend(process.env.AMDY_API_KEY!, { baseUrl: process.env.AMDY_API_URL!,});
export async function sendMagicLink(to: string, token: string) { const url = `https://app.acme.com/login?t=${token}`; return resend.emails.send({ to: [to], subject: "Sign in to Acme", html: `<p><a href="${url}">Click here to sign in</a></p>`, });}