Installation
npm install mailpass-sdk
Or with yarn:
yarn add mailpass-sdk
Quick Start — OTP Send & Verify
import MailPass from 'mailpass-sdk';
const client = new MailPass('mp_live_your_api_key_here');
// Send OTP
const response = await client.otp.send({
email: 'user@example.com',
purpose: 'login'
});
console.log(response.request_id);
// Verify OTP
const result = await client.otp.verify({
requestId: response.request_id,
otp: '123456'
});
if (result.success) {
console.log('Verified!', result.email);
}
Subscribers — List & Create
// List subscribers
const subscribers = await client.subscribers.list({
listId: 1, page: 1, perPage: 20
});
subscribers.data.forEach(sub => {
console.log(sub.email, sub.status);
});
// Create subscriber
const newSub = await client.subscribers.create({
email: 'new@example.com',
name: 'Jane Doe',
listId: 1,
tags: ['newsletter'],
doubleOptin: true
});
console.log(newSub.data.uuid);
Error Handling
import {
ApiError,
ValidationError,
RateLimitError,
} from 'mailpass-sdk';
try {
const response = await client.otp.send({ email: 'user@example.com' });
} catch (error) {
if (error instanceof ValidationError) {
console.error('Validation:', error.message, error.details);
} else if (error instanceof RateLimitError) {
console.error(`Rate limited. Retry after ${error.retryAfter}s`);
} else if (error instanceof ApiError) {
console.error(`API error [${error.code}]: ${error.message}`);
}
}
For the full API reference, see the API Documentation or the interactive Swagger UI.