JavaScript and TypeScript SDK for Poodle's email sending API.
- Installation
- Quick Start
- Features
- API Reference
- Error Handling
- Examples
- Development
- Contributing
- License
npm install @usepoodle/poodle-js
import { PoodleClient, PoodleError } from '@usepoodle/poodle-js';
// Initialize the client with your API key
const client = new PoodleClient({
apiKey: 'YOUR_POODLE_API_KEY_HERE',
});
// Send an email
async function sendEmail() {
try {
const response = await client.sendEmail({
from: 'sender@yourdomain.com',
to: 'recipient@example.com',
subject: 'Hello from Poodle!',
html: '<h1>Hello!</h1><p>This is a test email.</p>',
});
console.log('Email API call successful:', response.message);
} catch (error: any) {
console.error('Failed to send email:', error.message);
if (error instanceof PoodleError) {
console.error('Status Code:', error.statusCode);
console.error('Specific Details:', error.details);
}
}
}
sendEmail();
For more usage patterns, including sending text-only emails, see the examples directory.
- Intuitive API: Get started in minutes.
- TypeScript First: Robust type safety out-of-the-box.
- Modern Async: Clean async/await for non-blocking operations.
- Detailed Errors: Understand and debug issues quickly with PoodleError objects.
- Flexible Content: Send rich HTML or plain text emails easily.
The main class for interacting with the Poodle API.
new PoodleClient(options: PoodleClientOptions)
Options:
apiKey
(required): Your Poodle API keybaseUrl
(optional): Custom API base URL (defaults to production API)
sendEmail(options: SendEmailOptions): Promise<SendEmailResponse>
Options:
from
(required): Sender email addressto
(required): Recipient email addresssubject
(required): Email subject linehtml
(optional): HTML content of the emailtext
(optional): Plain text content of the email
At least one of html
or text
must be provided.
Response:
success
:boolean
- Indicates if the email was successfully queued (typicallytrue
for a successful call).message
:string
- A confirmation message from the API (e.g., "Email queued for sending").
The SDK throws PoodleError
instances for API-related errors. Each error includes:
message
: Human-readable error message (from the API'smessage
field).statusCode
: HTTP status code (if applicable).details
: Detailed error information or specific error code from the API (from the API'serror
field in the JSON response, if available).
Common error scenarios:
- Invalid API key (401)
- Rate limiting (429)
- Invalid email addresses (400)
- Account issues (402)
Check the examples directory for more usage examples.
# Install dependencies
npm install
# Run tests
npm test
# Build the package
npm run build
# Run linter
npm run lint
# Format code
npm run format
Contributions are welcome! Please read our Contributing Guide for details on the process for submitting pull requests and our Code of Conduct.
This project is licensed under the MIT License - see the LICENSE file for details.