How to send email with Node.js
Three ways — the Resend SDK, plain fetch, or Nodemailer over SMTP — all sending from your own domain.
1. Resend SDK
npm install resendimport { Resend } from "resend";
const nova = new Resend(process.env.NOVAMAIL_API_KEY, {
baseUrl: "https://api.novamail.nexaclouds.online",
});
const { data, error } = await nova.emails.send({
from: "Your Store <hello@mail.yourstore.com>",
to: "customer@example.com",
subject: "Welcome!",
html: "<p>Thanks for signing up.</p>",
});
2. Plain fetch (no dependencies)
const res = await fetch("https://api.novamail.nexaclouds.online/emails", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.NOVAMAIL_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": `welcome-${userId}`, // retries never send twice
},
body: JSON.stringify({ from: "hello@mail.yourstore.com", to: email, subject: "Welcome!", html }),
});
if (!res.ok) throw new Error((await res.json()).message);
3. Nodemailer over SMTP
import nodemailer from "nodemailer";
const transport = nodemailer.createTransport({
host: "postal.novamail.nexaclouds.online",
port: 587,
secure: false, // STARTTLS
auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS },
});
await transport.sendMail({ from: "hello@mail.yourstore.com", to: "customer@example.com", subject: "Welcome!", html: "<p>Hi</p>" });
Errors come back as JSON with statusCode, name and message — for example invalid_from_address when the domain isn't verified yet, or quota_exceeded (HTTP 429). Full reference: API docs.