lettermint
v1.5.1
Published
Official Lettermint Node.js SDK
Readme
Lettermint Node.js SDK
The official Node.js SDK for Lettermint.
Installation
npm install lettermintUsage
Initialize the SDK
import { Lettermint } from "lettermint";
const lettermint = new Lettermint({
apiToken: "your-api-token"
});Sending Emails
The SDK provides a fluent interface for sending emails:
const response = await lettermint.email
.from('[email protected]')
.to('[email protected]')
.subject('Hello from Lettermint')
.text('This is a test email sent using the Lettermint Node.js SDK.')
.send();
console.log(`Email sent with ID: ${response.message_id}`);
console.log(`Status: ${response.status}`);Advanced Email Options
const response = await lettermint.email
.from('John Doe <[email protected]>')
.to('[email protected]', '[email protected]')
.cc('[email protected]')
.bcc('[email protected]')
.replyTo('[email protected]')
.subject('Hello from Lettermint')
.html('<h1>Hello</h1><p>This is an HTML email.</p>')
.text('This is a plain text version of the email.')
.headers({
'X-Custom-Header': 'Custom Value',
})
.attach('attachment.txt', Buffer.from('Hello World').toString('base64'))
.attach('logo.png', Buffer.from('...').toString('base64'), 'logo') // Inline attachment
.idempotencyKey('unique-id-123')
.metadata({
foo: 'bar',
})
.tag('campaign-123')
.send();API Reference
Lettermint Class
The main entry point for the SDK.
const lettermint = new Lettermint({
apiToken: 'your-api-key',
baseUrl: 'https://api.lettermint.co/v1', // Optional
timeout: 30000, // Optional, in milliseconds
});Email Endpoint
Methods for sending emails:
from(email: string): Set the sender email addressto(...emails: string[]): Set one or more recipient email addressessubject(subject: string): Set the email subjecthtml(html: string | null): Set the HTML body of the emailtext(text: string | null): Set the plain text body of the emailcc(...emails: string[]): Set one or more CC email addressesbcc(...emails: string[]): Set one or more BCC email addressesreplyTo(...emails: string[]): Set one or more Reply-To email addressesheaders(headers: Record<string, string>): Set custom headers for the emailattach(filename: string, base64Content: string, content_id?: string): Attach a file to the email. Optionalcontent_idfor inline attachments.route(route: string): Set the routing key for the emailidempotencyKey(key: string): Set an idempotency key to prevent duplicate email sendsmetadata(metadata: Record<string, string>): Set metadata for the emailtag(tag: string): Set a tag for the emailsend(): Send the email and return a promise with the response
License
MIT
