@riuve/email
v1.0.0
Published
Riuve Email SDK - Send emails through Riuve
Downloads
56
Readme
@riuve/email
Riuve Email SDK - Send transactional and campaign emails through Riuve.
Installation
npm install @riuve/emailQuick Start
import Riuve from '@riuve/email';
// Initialize with your API key
Riuve.initialize('your-api-key');
// Send a single email
const result = await Riuve.send({
to: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome to our platform</h1>',
});
if (result.success) {
console.log('Email sent:', result.messageId);
} else {
console.error('Failed:', result.error);
}Configuration
Riuve.initialize('your-api-key', {
baseUrl: 'https://api.riuve.com', // default
timeout: 30000, // ms, default 30s
debugMode: true, // enables console logging
});Send Email with Variables
await Riuve.send({
to: '[email protected]',
subject: 'Hello {{name}}',
html: '<p>Hi {{name}}, your code is {{code}}</p>',
variables: {
name: 'Alice',
code: '123456',
},
locale: 'en',
});Send Batch Emails
const result = await Riuve.sendBatch([
{
to: '[email protected]',
subject: 'Welcome Alice',
html: '<p>Hi Alice!</p>',
},
{
to: '[email protected]',
subject: 'Welcome Bob',
html: '<p>Hi Bob!</p>',
},
]);
console.log(`Sent: ${result.sent}, Failed: ${result.failed}`);
if (result.errors) {
result.errors.forEach(({ to, error }) => {
console.error(`Failed to send to ${to}: ${error}`);
});
}Batches are automatically split into chunks of 100 and sent sequentially.
Using the Class Directly
import { RiuveEmailSDK } from '@riuve/email';
const sdk = RiuveEmailSDK.getInstance();
sdk.initialize('your-api-key');Types
import type {
RiuveEmailConfig,
SendEmailOptions,
SendEmailResponse,
SendBatchEmailResponse,
} from '@riuve/email';License
MIT
