Skip to content

📧 Emails module Email API

This module allows you to send emails.

Methods

Type declarations

ts
class Emails {
  constructor (protected mailchannels: MailChannelsClient);
  async send (options: EmailsSendOptions, dryRun?: boolean): Promise<EmailsSendResponse>;
  async queue (options: EmailsSendOptions): Promise<EmailsQueueResponse>;
  async sendAsync (options: EmailsSendOptions): Promise<EmailsQueueResponse>;
}
All type declarations

Response type declarations

ts
interface ErrorResponse {
  message: string;
  statusCode: number | null;
  type: ErrorType;
}
ts
type DataResponse<T> = {
  data: T;
  error: null;
} | {
  data: null;
  error: ErrorResponse;
};
ts
interface SuccessResponse {
  success: boolean;
  error: ErrorResponse | null;
}

Send type declarations

ts
interface EmailsSendRecipient {
  email: string;
  name?: string;
}
ts
type EmailsSendRecipientInput = EmailsSendRecipient[] | EmailsSendRecipient | string[] | string;
ts
interface EmailsSendDkim {
  domain?: string;
  privateKey?: string;
  selector?: string;
}
ts
interface EmailsSendPersonalization {
  bcc?: EmailsSendRecipientInput;
  cc?: EmailsSendRecipientInput;
  dkim?: EmailsSendDkim;
  envelopeFrom?: EmailsSendRecipient | string;
  from?: EmailsSendRecipient | string;
  headers?: Record<string, string>;
  replyTo?: EmailsSendRecipient | string;
  subject?: string;
  to: EmailsSendRecipientInput;
  template?: Required<Omit<EmailsSendTemplate, "type">>;
}
ts
interface EmailsSendAttachment {
  content: string;
  filename: string;
  type?: string;
  contentId?: string;
  disposition?: "attachment" | "inline";
}
ts
interface EmailsSendTracking {
  click?: {
    enable?: boolean;
  };
  open?: {
    enable?: boolean;
  };
}
ts
type EmailsSendTemplateType = "mustache";
ts
type EmailsSendTemplateValue = string | boolean | number | EmailsSendTemplateValue[] | { [key: string]: EmailsSendTemplateValue };
ts
interface EmailsSendTemplate {
  type: EmailsSendTemplateType;
  data?: Record<string, EmailsSendTemplateValue>;
}
ts
interface EmailsSendOptionsBase {
  attachments?: (EmailsSendAttachment | Promise<EmailsSendAttachment>)[];
  campaignId?: string;
  bcc?: EmailsSendRecipientInput;
  cc?: EmailsSendRecipientInput;
  dkim?: EmailsSendDkim;
  envelopeFrom?: EmailsSendRecipient | string;
  from: EmailsSendRecipient | string;
  headers?: Record<string, string>;
  personalizations?: EmailsSendPersonalization[];
  to?: EmailsSendRecipientInput;
  tracking?: EmailsSendTracking;
  replyTo?: EmailsSendRecipient | string;
  subject: string;
  template?: EmailsSendTemplate;
  transactional?: boolean;
}
ts
type EmailsSendTargetOptions =
  | {
    personalizations: (Omit<EmailsSendPersonalization, "template"> & { template?: never })[];
    to?: never;
    cc?: never;
    bcc?: never;
  }
  | {
    template: EmailsSendTemplate;
    personalizations: EmailsSendPersonalization[];
    to?: never;
    cc?: never;
    bcc?: never;
  }
  | {
    personalizations?: never;
    to: EmailsSendRecipientInput;
    cc?: EmailsSendRecipientInput;
    bcc?: EmailsSendRecipientInput;
  };
ts
interface EmailsSendContent {
  type: string;
  value: string;
}
ts
type EmailsSendOptions = EmailsSendOptionsBase & EmailsSendTargetOptions & (
  | {
    html: string;
    text?: string;
    content?: EmailsSendContent[];
  }
  | {
    html?: string;
    text: string;
    content?: EmailsSendContent[];
  }
  | {
    html?: string;
    text?: string;
    content: EmailsSendContent[];
  }
);
ts
type EmailsSendResponse = DataResponse<{
  rendered?: string[];
  requestId?: string;
  results?: {
    index?: number;
    messageId: string;
    reason?: string;
    status: "sent" | "failed";
  }[];
}>;

Queue type declarations

ts
type EmailsQueueResponse = DataResponse<{
  queuedAt: string;
  requestId: string;
}>;

Source

SourcePlaygroundDocsTests

Changelog

  • Unreleased on May 26, 2026

    • f49c49f feat(errors): introduce error type keys
  • v0.8.0 on May 23, 2026

    • 6b2b981 refactor(emails): deprecate sendAsync in favor of queue
    • 516eda2 feat: add Attachment helpers
    • ab66dc1 refactor: split internal utils into focused modules

Released under the MIT License.