Skip to main content

Send transactional email from Node.js and Next.js

Install @hatang/sdk, verify your sending domain once, then call emails.send from server code. The API is Resend-compatible, and SMTP works too.

npm install @hatang/sdk
import { Hatang } from "@hatang/sdk";

const hatang = new Hatang(); // reads HATANG_API_KEY

const { data, error } = await hatang.emails.send(
{
from: "Acme <[email protected]>", // a domain verified under Email → Domains
subject: "Order #1024 is confirmed",
html: "<p>Hi Lan, your order <strong>#1024</strong> is confirmed.</p>",
text: "Hi Lan, your order #1024 is confirmed.",
},
{ idempotencyKey: "order-1024-confirmation" }, // a retry never sends twice
);
if (error) throw new Error(`${error.name}: ${error.message}`);
console.log(data.id);

In Next.js, call it from a Server Action or a Route Handler, never from a client component: the API key is a secret.

Checklist​

  1. Create an API key with the email:send scope under Settings → API Keys and put it in HATANG_API_KEY.
  2. Add and verify your domain: publish the DKIM, SPF and return-path records it lists. See Domains.
  3. Send. Follow delivery with emails.get(id) or the email.delivered and email.bounced webhooks.

Go further​

  • Every field, attachments, scheduling and batches: Send email
  • Reusable templates with variables: Templates
  • React Email components: pass react: <WelcomeEmail /> instead of html (Node.js SDK)
  • Coming from Resend, SendGrid or Postmark: Migrate from Resend

View this page as Markdown