@sendara/node
v0.4.2
Published
Sendara API wrapper
Readme
Sendara Node.js Library
The official Node.js library for the Sendara API - a powerful email sending service.
Installation
Install the package with:
npm install @sendara/node
# or
yarn add @sendara/nodeUsage
The package needs to be configured with your account's API key, which is available on your Sendara organization settings page.
Basic Example
import Sendara from '@sendara/node'
const sendara = new Sendara('sendara_sk_...')
const email = await sendara.email.send({
from: {
email: '[email protected]',
name: 'Your Company'
},
to: [
{
email: '[email protected]',
name: 'Customer Name'
}
],
subject: 'Welcome to our service!',
html: '<h1>Welcome!</h1><p>Thanks for signing up.</p>',
text: 'Welcome! Thanks for signing up.'
})
console.log('Email sent:', email.id)Advanced Example with Attachments
const email = await sendara.email.send({
from: {
email: '[email protected]',
name: 'Support Team'
},
to: [
{ email: '[email protected]', name: 'John Doe' }
],
cc: [
{ email: '[email protected]', name: 'Manager' }
],
subject: 'Your Invoice #12345',
html: '<p>Please find your invoice attached.</p>',
attachments: [
{
filename: 'invoice.pdf',
content: Buffer.from('...').toString('base64'),
contentType: 'application/pdf'
}
],
replyTo: {
email: '[email protected]',
name: 'Support'
}
})Webhook Signature Verification
Sendara can optionally sign the webhook events it sends to your endpoint, allowing you to validate that they were not sent by a third party. You can read more about webhook security here.
Important: You must pass the raw request body, exactly as received from Sendara, to the verifyPayload() function. This will not work with a parsed (JSON) request body.
Express Example
const signature = req.headers['x-sendara-signature']
const event = sendara.webhook.verifyPayload(
req.body, // Raw buffer
signature,
webhookSecret
)
## API Reference
For complete API documentation, visit [docs.sendara.app](https://docs.sendara.app)