maylng
v0.3.0
Published
Maylng - TypeScript SDK for agentic email management. Create email addresses and send emails programmatically for AI agents.
Maintainers
Readme
Maylng - TypeScript SDK
TypeScript SDK for agentic email management - create email addresses and send emails programmatically for AI agents.
Features
- 🚀 Email Address Management: Create temporary and persistent email addresses
- 📧 Email Sending: Send emails with attachments, scheduling, and threading
- 🤖 AI Agent Focused: Built specifically for AI agent email workflows
- 📊 Analytics: Track email delivery, opens, and clicks
- 🔒 Secure: API key authentication with rate limiting
- 📱 Full TypeScript: Complete type safety and IntelliSense support
- ⚡ Production Ready: Error handling, retries, and monitoring
Installation
npm install maylngQuick Start
import { createMayl } from 'maylng';
// Initialize the SDK
const mayl = createMayl({
apiKey: 'your-api-key'
});
// Create a temporary email address
const tempEmail = await mayl.emailAddresses.create({
type: 'temporary',
expirationMinutes: 30
});
// Send an email
const sentEmail = await mayl.emails.send({
fromEmailId: tempEmail.id,
to: [{ email: '[email protected]', name: 'John Doe' }],
subject: 'Hello from AI Agent',
text: 'This email was sent by an AI agent using Maylng!'
});
console.log('Email sent:', sentEmail.id);Core Concepts
Email Addresses
- Temporary: Short-lived email addresses that expire automatically
- Persistent: Long-lived email addresses for ongoing communication
Email Operations
- Send: Send emails immediately or schedule for later
- Track: Monitor delivery status, opens, and clicks
- Thread: Maintain conversation threads for better organization
API Reference
MaylSDK
Main client class for interacting with the API.
Constructor
const mayl = createMayl(config: MaylConfig)Methods
healthCheck(): Verify API connectivitygetAccountInfo(): Get account details and usage statisticsupdateApiKey(apiKey: string): Update the API keyupdateBaseUrl(baseUrl: string): Update the base URL
Email Address Service
Accessible via mayl.emailAddresses
Methods_
create(options: CreateEmailAddressOptions): Create a new email addressget(id: string): Get email address detailslist(options?): List email addresses with filtering and paginationupdate(id: string, updates): Update email address metadata or statusdelete(id: string): Delete an email addressextend(id: string, minutes: number): Extend temporary email expiration
Email Service
Accessible via mayl.emails
Methods__
send(options: SendEmailOptions): Send an emailget(id: string): Get sent email detailslist(options?): List sent emails with filtering and paginationcancel(id: string): Cancel a scheduled emailresend(id: string): Resend a failed emailgetDeliveryStatus(id: string): Get delivery status and analytics
Configuration
interface MaylConfig {
apiKey: string; // Required: Your API key
baseUrl?: string; // Optional: Custom API base URL
timeout?: number; // Optional: Request timeout in ms (default: 30000)
}Error Handling
The SDK provides specific error types for different scenarios:
import {
AuthenticationError,
ValidationError,
RateLimitError,
EmailSendError
} from 'maylng';
try {
await mayl.emails.send(emailOptions);
} catch (error) {
if (error instanceof AuthenticationError) {
// Handle authentication issues
} else if (error instanceof RateLimitError) {
// Handle rate limiting
console.log('Retry after:', error.retryAfter);
}
}Error Types
AuthenticationError: Invalid API key or authentication failureAuthorizationError: Insufficient permissionsValidationError: Invalid input parametersRateLimitError: Rate limit exceededNetworkError: Network connectivity issuesServerError: Server-side errorsTimeoutError: Request timeoutEmailAddressError: Email address operation failuresEmailSendError: Email sending failures
Examples
See EXAMPLES.md for comprehensive usage examples including:
- Creating temporary and persistent email addresses
- Sending emails with attachments
- Scheduling emails
- Managing email threads
- Bulk operations
- Error handling patterns
Development
Prerequisites
- Node.js 18+
- npm or yarn
Setup
# Clone the repository
git clone https://github.com/maylng/mayl-sdk.git
cd mayl-sdk/ts
# Install dependencies
npm install
# Build the SDK
npm run build
# Run in development mode
npm run devScripts
npm run build: Build the TypeScript codenpm run dev: Build in watch modenpm run clean: Clean build artifacts
TypeScript Support
The SDK is built with TypeScript and provides complete type definitions. No additional @types packages are needed.
// Full IntelliSense support
const email: EmailAddress = await mayl.emailAddresses.create({
type: 'temporary', // Autocomplete: 'temporary' | 'persistent'
expirationMinutes: 30
});
// Type-safe error handling
if (error instanceof ValidationError) {
console.log(error.field); // string | undefined
console.log(error.code); // 'VALIDATION_ERROR'
}Rate Limiting
The API implements rate limiting to ensure fair usage:
- Email Creation: 100 requests per minute
- Email Sending: 1000 emails per hour
- API Calls: 10,000 requests per hour
When rate limited, the SDK will throw a RateLimitError with retry information.
Security
- All API requests use HTTPS encryption
- API keys should be stored securely (environment variables recommended)
- Never expose API keys in client-side code
- Rotate API keys regularly
Support
License
MIT License - see LICENSE for details.
Contributing
We welcome contributions! Please see our Contributing Guide for details.
