Back to roadmaps resend Course

Resend JS SDK and Custom Headers Cheat Sheet

This quick reference guide summarizes the most common patterns and configurations in Resend using the official Node.js SDK.


1. SDK Client Initialization

import { Resend } from "resend";

// Initialize the API client
const resend = new Resend("re_your-secret-key");

2. Dispatching a Single Email

await resend.emails.send({
  from: "Support Team <support@mycompany.com>",
  to: ["customer@gmail.com"],
  subject: "Updates on your order",
  html: "<p>Your order has shipped!</p>",
  // Optional custom mail headers configuration
  headers: {
    "X-Entity-Ref-ID": "order-12345",
  },
  attachments: [
    {
      filename: "invoice.pdf",
      content: "Invoice document content string",
    },
  ],
});

3. Dispatching Emails in Batches (Maximum 100 per request)

await resend.batch.send([
  {
    from: "Mailing List <news@mycompany.com>",
    to: ["recipient_a@gmail.com"],
    subject: "Newsletter Issue 1",
    html: "<p>Read details inside</p>",
  },
  {
    from: "Mailing List <news@mycompany.com>",
    to: ["recipient_b@gmail.com"],
    subject: "Newsletter Issue 1",
    html: "<p>Read details inside</p>",
  },
]);

4. Common Error Codes Reference

Error Code Status Description Action Required
403 Unauthorized Invalid or missing API key token Regenerate key in Resend
422 Unprocessable Domain not verified Verify DNS SPF/DKIM records
429 Rate Limit Sending quota exceeded Upgrade plan or throttle queue
500 Server Error Resend internal server error Monitor status.resend.com
Published on Last updated: