/** * Options for sending a single email or one item in a batch. */ interface MailOptions { /** * Sender address. * - Custom domains (e.g. `hi@aastar.io`) must be verified in the Resend dashboard * (SPF/DKIM/DMARC DNS records) before use. * - Without domain verification, use `onboarding@resend.dev` (test only). */ from: string; to: string | string[]; subject: string; html?: string; text?: string; cc?: string | string[]; bcc?: string | string[]; replyTo?: string; attachments?: Array<{ filename: string; content: Buffer | string; }>; headers?: Record; tags?: Array<{ name: string; value: string; }>; /** * ISO 8601 datetime with timezone offset for scheduled delivery. * Example: `"2026-06-01T09:00:00+07:00"` or `"2026-06-01T02:00:00Z"`. * Must be a future timestamp; Resend rejects past or timezone-ambiguous values. */ scheduledAt?: string; /** * Idempotency key for agent retry scenarios. * Duplicate calls with the same key will not send the email again. * Only supported by `send()` — ignored by `sendBatch()`. */ idempotencyKey?: string; } /** Result of a successful single send or one item in a batch result. */ interface SendResult { id: string; } /** Per-item result for sendBatch — includes index for error attribution. */ interface BatchSendResult { index: number; id: string; } /** Error thrown when one or more batch items fail. */ declare class BatchSendError extends Error { readonly failures: Array<{ index: number; reason: string; }>; constructor(message: string, failures: Array<{ index: number; reason: string; }>); } /** * ResendMailer — server-side email utility built on the Resend API. * * Install: `pnpm add @aastar/email` * * @example * ```ts * import { ResendMailer } from '@aastar/email'; * * const mailer = ResendMailer.fromEnv(); // reads RESEND_API_KEY * await mailer.send({ * from: 'hi@aastar.io', * to: 'user@example.com', * subject: 'Welcome', * html: '

Hello!

', * }); * ``` * * @example Agent tool with idempotency * ```ts * await mailer.send({ * from: 'hi@aastar.io', * to: 'user@example.com', * subject: 'Your receipt', * html: '...', * idempotencyKey: `receipt-${txHash}`, * }); * ``` */ declare class ResendMailer { private client; /** @param apiKey - Resend API key from https://resend.com/api-keys */ constructor(apiKey: string); /** * Send a single email. * @returns `{ id }` — Resend email ID for delivery status queries */ send(options: MailOptions): Promise; /** * Send a batch of emails (max 100 per request). * `idempotencyKey` is stripped per item — not supported by the batch endpoint. * * @throws {BatchSendError} if any item is missing an ID in the response * @returns Results in the same order as the input */ sendBatch(emails: MailOptions[]): Promise; /** * Create a ResendMailer from the `RESEND_API_KEY` environment variable. * Recommended for server-side and CI usage. * @throws if the environment variable is not set */ static fromEnv(): ResendMailer; } export { BatchSendError, type BatchSendResult, type MailOptions, ResendMailer, type SendResult };