maileroo
v0.0.3
Published
This repository contains Node.js SDK to help you integrate with Maileroo's email sending API efficiently and effectively.
Readme
Maileroo Node.js Client
Overview
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.
Features
- 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
Installation
npm install mailerooUsage
Initialization
const { MailerooClient } = require('maileroo');
const apiKey = 'your_api_key';
const mailerooClient = MailerooClient.getClient(apiKey);Sending an Email
Basic Email
await mailerooClient
.setFrom('John Doe', '[email protected]')
.setTo('Jane Smith', '[email protected]')
.setSubject('Hello World!')
.setHtml('<h1>Welcome</h1>')
.setPlain('Welcome')
.sendBasicEmail();Template Email
await mailerooClient
.setFrom('John Doe', '[email protected]')
.setTo('Jane Smith', '[email protected]')
.setTemplateId('template_id')
.setTemplateData({ name: 'Jane' })
.sendTemplateEmail();Managing Attachments
mailerooClient.addAttachment('./path/to/file.pdf', 'file.pdf', 'application/pdf');
mailerooClient.addInlineAttachment('./path/to/image.png', 'image.png', 'image/png');Contact Management
Create Contact
await mailerooClient.createContact('list_id', { email: '[email protected]', name: 'Jane Smith' });Update Contact
await mailerooClient.updateContact('list_id', '[email protected]', { name: 'Jane Doe' });Delete Contact
await mailerooClient.deleteContact('list_id', '[email protected]');Get Contact
const contact = await mailerooClient.getContact('list_id', '[email protected]');
console.log(contact);List Contacts
const contacts = await mailerooClient.listContacts('list_id', 'query', 1);
console.log(contacts);Error Handling
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);
}License
This library is distributed under the MIT License. Feel free to use and modify it.
