Send with Node.js

The API is one POST with a JSON body, so plain fetch does it. The SDK stays optional and your code stays portable.

Want it even shorter? The official Node.js SDK (npm install camelmailer) wraps this in a typed client with a { data, error } result: await camelmailer.emails.send({ from, to, subject }). The plain-fetch version below stays dependency-free.

The basic send

mailer.js
// CAMELMAILER_URL=https://mail.yourdomain.com
// CAMELMAILER_KEY=<your server API credential>

export async function sendMail(message) {
  const res = await fetch(
    `${process.env.CAMELMAILER_URL}/api/v2/server/messages`,
    {
      method: 'POST',
      headers: {
        'X-Server-API-Key': process.env.CAMELMAILER_KEY,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(message),
    },
  );

  const { status, data, error } = await res.json();
  if (status !== 'success') {
    throw new Error(`${error.code}: ${error.message}`);
  }
  return data;
}
usage
await sendMail({
  from: 'billing@yourdomain.com',
  to: [user.email],
  subject: 'Your receipt',
  text_body: `Thanks! You paid €${amount}.`,
});

Handle errors by code

error.code is stable, so build your retry/alert logic on it:

// ValidationError / ParameterMissing → fix the payload (do not retry)
// Unauthorized → rotate/check the credential
// anything network-level → retry with backoff; sends are queued server-side

With a stored template

await sendMail === same function, different endpoint:
  /api/v2/server/messages/with_template
  { from, to, template: 'welcome', template_model: { name: 'Ada' } }
Sending from Next.js or serverless? Call CamelMailer from server code only (API routes, server actions), because the credential must never reach the browser. Full field reference: Messages API.