Send email with Resend
Transactional email, like sign-up confirmations and receipts, is a common need. Resend sends it with a small API. This example sends one HTML email; the onboarding@resend.dev sender works for testing without verifying a domain. Set RESEND_API_KEY before running.
import { Resend } from "npm:resend";
const resend = new Resend(Deno.env.get("RESEND_API_KEY")!);send returns either data with the message id, or an error. Check error rather than relying on a thrown exception.
const { data, error } = await resend.emails.send({
from: "onboarding@resend.dev",
to: "delivered@resend.dev",
subject: "Hello from Deno",
html: "<p>This email was sent with <strong>Resend</strong> from Deno.</p>",
});
if (error) {
console.error("Failed to send:", error);
} else {
console.log("Sent message:", data?.id);
}Run this example locally using the Deno CLI:
deno run -N -E https://docs.deno.com/examples/scripts/send_email.ts