Skip to content
Hermesmail
Docs pages

Node.js

Hermesmail implements a wire-compatible API for sending emails, batches and attachments, so Node.js applications call Hermesmail directly through the official Resend SDK pointed at https://api.hermesmail.app.

Install

Install the resend package at version 6.39.0 which matches the version verified by Hermesmail's automated Node SDK compatibility suite:

npm install [email protected]

Client configuration

Point the SDK at https://api.hermesmail.app and pass a Hermesmail API key (hm_...). Both environment-based configuration and explicit constructor options are supported.

Configure with RESEND_BASE_URL

Export RESEND_BASE_URL and HERMESMAIL_API_KEY in the runtime environment:

export RESEND_BASE_URL=https://api.hermesmail.app
export HERMESMAIL_API_KEY="hm_..."

When RESEND_BASE_URL is set, new Resend(process.env.HERMESMAIL_API_KEY) automatically routes every SDK call to https://api.hermesmail.app. The four runnable examples below rely on this environment variable.

Configure with the baseUrl option

To set the endpoint directly in application code instead of the environment, pass { baseUrl } as the second constructor argument:

import { Resend } from 'resend';

const resend = new Resend(process.env.HERMESMAIL_API_KEY, {
  baseUrl: 'https://api.hermesmail.app',
});

Trailing slashes on baseUrl are also accepted. Hermesmail is an independent service and is not affiliated with Resend.

Send an email

Send a single transactional message from a verified domain using resend.emails.send:

import { Resend } from 'resend';

// Reads RESEND_BASE_URL from the environment (set to https://api.hermesmail.app).
const resend = new Resend(process.env.HERMESMAIL_API_KEY);

const { data, error } = await resend.emails.send({
  from: 'Orders <[email protected]>',
  to: ['[email protected]'],
  subject: 'Order confirmed',
  text: 'Your order has been received.',
});

if (error) {
  console.error(JSON.stringify(error));
  process.exitCode = 1;
} else {
  console.log(JSON.stringify(data));
}

The call resolves to { data: { id }, error: null } when accepted.

Send a batch

Send up to 100 messages in a single HTTP request with resend.batch.send. Every accepted recipient still counts against your team's sending quotas, and batch items do not support attachments; see Limits.

import { Resend } from 'resend';

// Reads RESEND_BASE_URL from the environment (set to https://api.hermesmail.app).
const resend = new Resend(process.env.HERMESMAIL_API_KEY);

const { data, error } = await resend.batch.send([
  {
    from: 'Alerts <[email protected]>',
    to: ['[email protected]'],
    subject: 'First batch message',
    text: 'First recipient in the batch.',
  },
  {
    from: 'Alerts <[email protected]>',
    to: ['[email protected]'],
    subject: 'Second batch message',
    text: 'Second recipient in the batch.',
  },
]);

if (error) {
  console.error(JSON.stringify(error));
  process.exitCode = 1;
} else {
  console.log(JSON.stringify(data));
}

The response returns { data: { data: [{ id }, ...] }, error: null } in request order.

Send with an attachment

Include files on individual messages through the attachments array. The Node SDK automatically base64-encodes Buffer and Uint8Array values, or forwards pre-encoded base64 strings unchanged. Total message size — including headers, bodies and base64-encoded attachments — must stay within 40 MB as described in Limits.

import { Resend } from 'resend';

// Reads RESEND_BASE_URL from the environment (set to https://api.hermesmail.app).
const resend = new Resend(process.env.HERMESMAIL_API_KEY);

const { data, error } = await resend.emails.send({
  from: 'Billing <[email protected]>',
  to: ['[email protected]'],
  subject: 'Your receipt',
  text: 'Find your plain-text receipt attached.',
  attachments: [
    {
      filename: 'receipt.txt',
      content: Buffer.from('Receipt #1001\n', 'utf8'),
      contentType: 'text/plain',
    },
  ],
});

if (error) {
  console.error(JSON.stringify(error));
  process.exitCode = 1;
} else {
  console.log(JSON.stringify(data));
}

Handle errors

SDK methods return { data, error } rather than throwing on HTTP 4xx or 5xx responses. Inspect error.name for programmatic handling and log error.message for diagnostics; every error name and HTTP status is listed in Errors.

import { Resend } from 'resend';

// Reads RESEND_BASE_URL from the environment (set to https://api.hermesmail.app).
const resend = new Resend(process.env.HERMESMAIL_API_KEY);

// Passing an empty recipient list produces a 422 validation_error response.
const { data, error } = await resend.emails.send({
  from: 'Orders <[email protected]>',
  to: [],
  subject: 'Missing recipient example',
  text: 'Demonstrates inspecting error.name and error.statusCode.',
});

if (error) {
  console.log(
    JSON.stringify({
      statusCode: error.statusCode,
      name: error.name,
      message: error.message,
    }),
  );
} else {
  console.error('Expected an error response, received:', JSON.stringify(data));
  process.exitCode = 1;
}