DocumentationSend with the SDK
Send with the SDK
mailingcore-js — init, send, and error handling.
The mailingcore-js SDK sends transactional emails from JavaScript or TypeScript. It is browser-safe, dependency-free, and under 1 KB gzip.
Installation
npm install mailingcore-js
Configuration
import { MailingCore } from 'mailingcore-js'
MailingCore.init({
apiKey: process.env.MAILINGCORE_API_KEY!,
baseUrl: 'https://api.mailingcore.com', // optional
timeout: 30000, // optional, ms
})
Send an email
const result = await MailingCore.send({
to: '[email protected]',
subject: 'Welcome',
htmlBody: '<h1>Hello</h1>',
textBody: 'Hello',
fromEmail: '[email protected]',
idempotencyKey: crypto.randomUUID(),
templateVersionId: 'clxversion...', // optional
})
console.log(result.id) // log id
console.log(result.status) // "QUEUED"
Next.js (Server Action)
'use server'
import { MailingCore } from 'mailingcore-js'
MailingCore.init({ apiKey: process.env.MAILINGCORE_API_KEY! })
export async function sendWelcome(email: string, name: string) {
return MailingCore.send({
to: email,
subject: 'Welcome',
htmlBody: `<h1>Hello, ${name}</h1>`,
})
}
Errors
import { MailingCore, MailingCoreError } from 'mailingcore-js'
try {
await MailingCore.send({ ... })
} catch (err) {
if (err instanceof MailingCoreError) {
console.error(err.status, err.detail)
}
}
Logs
const { data, meta } = await MailingCore.getLogs({ page: 1, limit: 20 })
Requires the email:read scope on the underlying API key.
The API key resolves the tenant automatically; you do not need X-Tenant-Id when using only Bearer mc_live_ / mc_test_.
Equivalent REST reference: Send email.