Email API quickstart
Choose Node.js, Next.js or cURL to make your first request against a running SendHQ installation.
Before your first request
Use Node.js 20 or newer for the SDK examples. Get an API origin and key from the operator of your installation, enroll the sending domain and wait for verified status. Set these variables in your server environment.
| 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. |
Node.js
Install the SDK tarball supplied with your release. Its package name is mailforge. The client reads the base URL and key from the server environment.
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);Next.js App Router
Create a server-only helper, then call it after a confirmed order. Use the order ID to recognize a retry of the same receipt.
import "server-only";
import { MailForge } from "mailforge";
export async function sendReceipt(orderId: string, recipient: string) {
const from = process.env.MAILFORGE_FROM;
if (!from) throw new Error("Set MAILFORGE_FROM.");
return new MailForge().send({
from,
to: recipient,
subject: "Order confirmed",
text: "We received your order.",
}, { idempotencyKey: `receipt-${orderId}` });
}cURL
From Bash with the four variables exported, run this request. It uses Node.js to safely encode the example JSON and passes the bearer header on standard input.
curl --fail-with-body -X POST "$MAILFORGE_BASE_URL/api/emails" \
--header @- \
-H 'Content-Type: application/json' \
-H 'Idempotency-Key: quickstart-curl-001' \
--data "$(node -p 'JSON.stringify({from:process.env.MAILFORGE_FROM,to:process.env.MAILFORGE_TO,subject:"Hello",text:"Sent with cURL."})')" \
<<<"Authorization: Bearer $MAILFORGE_API_KEY"Expected response: HTTP 202 and an object with an id and object: "email". Save the ID. A read-scoped key can fetch GET /api/emails/{id} for status and history.
Sending limits and common errors
Each newly accepted email uses one send. Read the trial and subscription limits when handling a plan or quota error.
| Response | Action |
|---|---|
403 domain_not_verified | Check the sending domain’s records and wait for verification. |
402 upgrade_required | Check your trial and subscription status with GET /api/billing/credits. A plan limit returns 402 quota_exceeded. |
409 idempotency_conflict | Compare the payload with the first submission that used this key. |
429 rate_limited | Wait for Retry-After, then retry the same operation with its original key. |
Inspect delivery and bounce events or verify incoming webhooks.