Kraiter
SDK Reference

Send

SDK reference for sending transactional emails through Kraiter.

The kraiter.send namespace provides methods for sending one-off transactional emails. Use this for emails triggered by a user action — password resets, order confirmations, welcome emails, and similar.

transactional

Sends a single transactional email to one recipient using a pre-defined template.

const result = await kraiter.send.transactional({
  to: 'alice@example.com',
  templateId: 'tmpl_welcome',
  variables: {
    firstName: 'Alice',
    activationUrl: 'https://app.example.com/activate?token=abc',
  },
});

console.log(result.sendId); // unique ID for this send
console.log(result.status); // e.g. "queued"

Parameters

ParameterTypeRequiredDescription
tostringYesThe recipient email address.
templateIdstringYesThe ID of the template to render.
variablesRecord<string, unknown>NoTemplate variables to interpolate into the subject line and body.
ignoreUnsubscribebooleanNoWhen true, the email is sent even if the contact has unsubscribed. Use only for legally required messages such as invoices or security alerts. Defaults to false.

Returns

Promise<SendResult> — information about the queued send.

SendResult object

FieldTypeDescription
sendIdstringA unique identifier for this send. Use it to look up delivery status.
statusstringThe initial status of the send (typically "queued").
tostringThe recipient email address.
templateIdstringThe template that was used.

Errors

CodeWhen
NOT_FOUNDThe templateId does not match any template.
VALIDATION_ERRORThe to address is invalid or a required template variable is missing.
FORBIDDENYour sending domain is not verified.

Error handling example

import { KraiterError } from '@kraiter/sdk';

try {
  await kraiter.send.transactional({
    to: 'alice@example.com',
    templateId: 'tmpl_receipt',
    variables: { orderId: '12345' },
  });
} catch (error) {
  if (error instanceof KraiterError) {
    switch (error.code) {
      case 'NOT_FOUND':
        console.error('Template not found — check the templateId');
        break;
      case 'VALIDATION_ERROR':
        console.error('Invalid request:', error.message);
        break;
      case 'FORBIDDEN':
        console.error('Domain not verified — complete domain setup first');
        break;
      default:
        console.error('Unexpected error:', error.message);
    }
  }
}

Unsubscribe behaviour

By default, the SDK respects contact suppression. If the recipient has unsubscribed, the send is silently skipped and the returned status will reflect this.

Set ignoreUnsubscribe: true only when the email is legally required — for example, a payment receipt or a security notification. Misusing this flag may harm your sender reputation.

// Send a legally required invoice email regardless of unsubscribe status
await kraiter.send.transactional({
  to: 'alice@example.com',
  templateId: 'tmpl_invoice',
  variables: { invoiceId: 'INV-2025-001' },
  ignoreUnsubscribe: true,
});

Template variables

Variables passed in the variables object are interpolated into the template's subject line and body using Liquid syntax. If your template references a variable that is not provided, it will render as an empty string.

// Template subject: "Your order {{ orderId }} has shipped"
// Template body contains: "Hi {{ firstName }}, ..."
await kraiter.send.transactional({
  to: 'alice@example.com',
  templateId: 'tmpl_shipping',
  variables: {
    firstName: 'Alice',
    orderId: 'ORD-9876',
    trackingUrl: 'https://track.example.com/abc',
  },
});

See the Templates guide for more on Liquid syntax and variable usage.