Welcome to the official Node.js SDK for Maileroo, a powerful and flexible email sending API. This SDK allows you to easily integrate Maileroo's email sending capabilities into your PHP applications.
- Send basic and template-based emails
- Add attachments and inline attachments
- Manage contacts (create, update, delete, and list)
- Generate unique reference IDs for email tracking
- Chainable methods for setting email data
npm install maileroo
const { MailerooClient } = require('maileroo');
const apiKey = 'your_api_key';
const mailerooClient = MailerooClient.getClient(apiKey);
await mailerooClient
.setFrom('John Doe', 'john@example.com')
.setTo('Jane Smith', 'jane@example.com')
.setSubject('Hello World!')
.setHtml('<h1>Welcome</h1>')
.setPlain('Welcome')
.sendBasicEmail();
await mailerooClient
.setFrom('John Doe', 'john@example.com')
.setTo('Jane Smith', 'jane@example.com')
.setTemplateId('template_id')
.setTemplateData({ name: 'Jane' })
.sendTemplateEmail();
mailerooClient.addAttachment('./path/to/file.pdf', 'file.pdf', 'application/pdf');
mailerooClient.addInlineAttachment('./path/to/image.png', 'image.png', 'image/png');
await mailerooClient.createContact('list_id', { email: 'jane@example.com', name: 'Jane Smith' });
await mailerooClient.updateContact('list_id', 'jane@example.com', { name: 'Jane Doe' });
await mailerooClient.deleteContact('list_id', 'jane@example.com');
const contact = await mailerooClient.getContact('list_id', 'jane@example.com');
console.log(contact);
const contacts = await mailerooClient.listContacts('list_id', 'query', 1);
console.log(contacts);
The library throws errors if an API request fails. Use try-catch blocks to handle these errors gracefully:
try {
await mailerooClient.sendBasicEmail();
} catch (error) {
console.error(error.message);
}
This library is distributed under the MIT License. Feel free to use and modify it.