Prepare your sender
In the dashboard, register your sending domain and publish its DNS records. Wait for its status to become verified. If your SES account is in the sandbox, verify the recipient with SES too.
On your server, set MAILFORGE_BASE_URL to the origin of this installation, MAILFORGE_API_KEY to a send-scoped key for this environment, and MAILFORGE_FROM to a mailbox on your verified domain. For the examples below, set MAILFORGE_TO to a recipient you control. Use Node.js 20 or later.
Node.js
Install the SDK tarball from your MailForge release. To build it from this checkout, run npm ci --prefix sdk && npm pack ./sdk, then npm install /path/to/mailforge-0.1.0.tgz in your application.
Save as send.mjs and run node send.mjs. A stable application event ID lets you safely retry the same message within 24 hours. Use a fresh event ID for each distinct message.
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);
The ID acknowledges a queued message. Use a read-scoped key to call mailer.getEmail(email.id) for its current status and event history.
Next.js App Router
Install the SDK tarball and server-only. Save this helper in lib/send-receipt.ts. Call it from your authenticated server-side order flow after loading a confirmed order and its recipient from your database. Keep the API key in a server environment variable.
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
With the same server environment variables set, use Bash to submit a single test message.
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"
Check your sending allowance
Start with a seven-day trial and up to 2,000 accepted emails per UTC day. A new accepted submission counts once. Replaying the same accepted email uses no additional allowance. Call mailer.getCredits() with a read-scoped key to see your usage, trial end and current plan.
A new send after trial expiry returns HTTP 402 upgrade_required. Reaching an allowance returns HTTP 402 quota_exceeded. Upgrade from the dashboard or call mailer.createSubscriptionCheckout({ idempotencyKey: purchaseUuid }) on the server with a keys:manage key. Save the UUID for retries and open the returned checkout URL. Buying the $7 USD monthly subscription starts billing immediately and includes 50,000 sends per UTC calendar month.
Handle delivery and errors
A successful send returns HTTP 202. An unverified sender returns HTTP 403 with domain_not_verified. The SDK exposes API errors as MailForgeError with status, type, and message. For HTTP 429, wait the number of seconds in retryAfterSeconds and reuse the operation’s idempotency key. The OpenAPI specification lists response schemas and permissions.