Send email with Node.js
Send a welcome email with the TypeScript SDK and keep the message ID so your application can follow its delivery.
Install the server-side SDK
Use Node.js 20 or newer and the SDK tarball from your SendHQ release. If you have the source checkout, run these commands from its root to build the tarball.
npm ci --prefix sdk
npm pack ./sdkIn the Node.js application directory, install the resulting file. Replace the example path with its location on your machine.
npm install /path/to/mailforge-0.1.0.tgzPrepare a verified sender
| Variable | Value to supply |
|---|---|
MAILFORGE_BASE_URL | The HTTPS origin of your running API installation, or HTTP on loopback for local development. This public documentation site serves static pages. |
MAILFORGE_API_KEY | A server-side bearer key for that deployment with the send scope. |
MAILFORGE_FROM | A sender address on a verified domain that belongs to your account. |
MAILFORGE_TO | A recipient you control. In the SES sandbox, use a verified recipient or the SES mailbox simulator. |
If your account has not enrolled a domain, use POST /api/domains with a send-scoped key, publish the returned DNS values and wait for verification. Review the three domain records.
Send a message from Node.js
Save the following as send.mjs. The stable key in this first example identifies one welcome email. For a real signup, store a unique welcome-event ID with the signup and reuse it for retries.
import { MailForge } from "mailforge";
const mailer = new MailForge();
const email = await mailer.send({
from: process.env.MAILFORGE_FROM,
to: process.env.MAILFORGE_TO,
subject: "Welcome to MailForge",
text: "Your first message is on its way.",
}, { idempotencyKey: "quickstart-welcome-001" });
console.log(email.id);node send.mjsThe returned UUID belongs to the queued message. Save it alongside your signup record. A 202 confirms that the request was accepted. The receiving mail server can still reject the message later.
Check the delivery
Give a reporting process its own read-scoped key. Run this lookup with the saved UUID in MAILFORGE_EMAIL_ID and the read key in MAILFORGE_API_KEY.
import { MailForge } from "mailforge";
const mailer = new MailForge();
const email = await mailer.getEmail(process.env.MAILFORGE_EMAIL_ID);
console.log(email.status);
for (const event of email.events) {
console.log(event.created_at, event.type);
}A delivered event records a provider delivery confirmation. An open or a click is outside this event history. For asynchronous handling, verify a signed delivery webhook.
Retry the same operation safely
Keep both the key and message content stable across retries for 24 hours from acceptance. Changing the payload under the same key returns 409. On a 429, the SDK exposes the wait in MailForgeError.retryAfterSeconds. Schedule the retry for that time.
A newly accepted message consumes one unit. An idempotent replay of the same ID consumes zero. See the sending limits.