@lessly/mail
v0.1.0
Published
TypeScript SDK client for the Lessly Mail API
Readme
@lessly/mail
TypeScript SDK for the Lessly Mail API.
import { Mail } from '@lessly/mail';
const mail = new Mail('lmk_live_…', { productId: 'p-123' });
const { id } = await mail.emails.send({
from: 'Acme <[email protected]>',
to: '[email protected]',
subject: 'Welcome',
html: '<p>Hello</p>',
});
const email = await mail.emails.get(id);Templates
const tpl = await mail.templates.create({
name: 'Welcome',
subject: 'Welcome, {{FIRST_NAME}}',
html: '<p>Hello {{FIRST_NAME}}</p>',
variables: [{ name: 'FIRST_NAME', type: 'string' }],
});
await mail.templates.publish(tpl.id);
await mail.emails.send({
from: 'Acme <[email protected]>',
to: '[email protected]',
template: { id: tpl.id, variables: { FIRST_NAME: 'Sam' } },
});create returns a draft; only drafts can be edited via update (a PATCH
on a published template throws ConflictError). publish is idempotent. The
template arm omits subject — the server renders it from the template.
React Email
import { WelcomeEmail } from './emails/Welcome';
await mail.emails.send({
from: 'Acme <[email protected]>',
to: '[email protected]',
subject: 'Welcome',
react: <WelcomeEmail name="Sam" />,
});The component is rendered to HTML + plain text locally; React never goes over
the wire. Callers using { react } must have react and react-dom
installed — they are optional peer dependencies of this package.
Options
new Mail(apiKey, { productId, baseUrl?, timeout?, retry? })
productId(required) — path segment on the public edge.baseUrl— defaulthttps://public.lessly.dev.timeout— default30000ms.retry—{ maxAttempts?, initialDelay?, maxDelay? }.
Publishing
Published to the Lessly SDK Registry (Google Artifact Registry). A live publish requires GAR write credentials; see the team's release process.
