@ircg/tes
v1.28.2
Published
Transactional Email Service SDK for IRCG
Downloads
624
Maintainers
Readme
@ircg/tes
TypeScript/JavaScript SDK for the IRCG Transactional Email Service.
Installation
npm install @ircg/tesBasic usage
import { TESClient } from '@ircg/tes'
const tes = new TESClient({ apiKey: process.env.IRCG_API_KEY!, lang: 'en' })
const { email_sent: email, error } = await tes.send({
sender: '[email protected]',
recipients: ['[email protected]'],
subject: 'Order confirmed',
html: '<h1>Thank you for your order</h1>',
text: 'Thank you for your order',
fields: ['id', 'sender', 'recipients', 'subject', 'createdAt'],
})
if (error) console.error(error.message)
else console.log(email.id)Use sendText() or sendHtml() when only one content format is needed:
await tes.sendText({
to: '[email protected]',
from: '[email protected]',
subject: 'Plain-text message',
text: 'Hello from IRCG',
fields: ['id', 'createdAt'],
})
await tes.sendHtml({
to: '[email protected]',
from: '[email protected]',
subject: 'HTML message',
html: '<p>Hello from IRCG</p>',
fields: ['id', 'createdAt'],
})Every send method has an Unsafe counterpart that throws on failure. Safe methods return either the requested data or error.
Input and response fields
send() accepts sender, recipients, subject, at least one of html or text, and optionally carbon_copy, reply_to, fields, and lang.
Available response fields are id, sender, recipients, subject, createdAt, serviceId, domainId, carbonCopy, replyTo, sesMessageId, and customerId.
Dry run
Dry-run mode does not make an HTTP request or consume credits:
const tes = new TESClient({ apiKey: 'unused-in-dry-run', dryRun: true })
const result = await tes.send({
sender: '[email protected]',
recipients: '[email protected]',
subject: 'Preview',
text: 'Preview content',
fields: ['id', 'subject'],
})
if (!result.error) console.log(result.email_sent.id) // "dry-run"Keep production API keys on the server. The client supports lang: 'es' | 'en' globally and on individual safe calls.
Limits and costs
The service consumes 10 credits for each address supplied in recipients and carbon_copy. The default rate limit is 60
requests per 60 seconds and 2,000 per 3,600 seconds per API key; both windows apply independently. Approved
organization-specific limits may differ.
