Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@upyo/lettermint

JSR npm

Lettermint transport for the Upyo email library.

Features

  • Single and batch email sending via Lettermint's HTTP API
  • Idempotency key support through Message.idempotencyKey
  • Cross-runtime compatibility (Node.js, Deno, Bun, edge functions)
  • Rich content support: HTML emails, attachments, inline images, and custom headers
  • Lettermint route, tag, metadata, and tracking settings
  • Retry logic with exponential backoff
  • Type-safe configuration with sensible defaults

Installation

npm  add       @upyo/core @upyo/lettermint
pnpm add       @upyo/core @upyo/lettermint
yarn add       @upyo/core @upyo/lettermint
deno add --jsr @upyo/core @upyo/lettermint
bun  add       @upyo/core @upyo/lettermint

Usage

import { createMessage } from "@upyo/core";
import { LettermintTransport } from "@upyo/lettermint";
import process from "node:process";

const message = createMessage({
  from: "sender@example.com",
  to: "recipient@example.net",
  subject: "Hello from Upyo!",
  content: { text: "This is a test email." },
  idempotencyKey: "welcome-recipient-example-net",
});

const transport = new LettermintTransport({
  apiToken: process.env.LETTERMINT_API_TOKEN!,
});

const receipt = await transport.send(message);
if (receipt.successful) {
  console.log("Message sent with ID:", receipt.messageId);
} else {
  console.error("Send failed:", receipt.errorMessages.join(", "));
}

Sending multiple emails

const messages = [message1, message2, message3];

for await (const receipt of transport.sendMany(messages)) {
  if (receipt.successful) {
    console.log(`Email sent with ID: ${receipt.messageId}`);
  } else {
    console.error(`Email failed: ${receipt.errorMessages.join(", ")}`);
  }
}

Configuration

See the Lettermint docs for more information about configuration options.

Available options

  • apiToken: Your Lettermint project sending API token
  • baseUrl: Lettermint API base URL (default: https://api.lettermint.co)
  • timeout: Request timeout in milliseconds (default: 30000)
  • retries: Number of retry attempts (default: 3)
  • headers: Additional HTTP headers
  • route: Lettermint route for sent messages
  • tag: Default Lettermint tag when a message has no Message.tags
  • metadata: Metadata to track with sent messages
  • settings: Lettermint tracking settings (trackOpens, trackClicks)