Email API
Email API Getting Started
Learn how to send transactional and marketing emails with the OMX Email API.
Email API
Build with confidence
The OMX Email API provides reliable, scalable email delivery with enterprise-grade infrastructure. Send transactional emails, marketing campaigns, and automated sequences with high deliverability rates.
Installation & Setup
Get started with email delivery in just a few steps.
1
Install the packages
Install Core SDK and Email module
typescript
1# npm
2npm install @omx-sdk/core @omx-sdk/email
3
4# yarn
5yarn add @omx-sdk/core @omx-sdk/email
6
7# pnpm
8pnpm add @omx-sdk/core @omx-sdk/email
2
Initialize the Email module
Set up your OMX client and Email module
typescript
1import { OMXClient } from '@omx-sdk/core';
2import { Email } from '@omx-sdk/email';
3
4const omx = new OMXClient({
5 clientId: 'your_client_id',
6 secretKey: 'your_secret_key'
7});
8
9const email = new Email(omx);
3
Send your first email
Send a simple transactional email
typescript
1const result = await email.send({
2 to: 'customer@example.com',
3 from: 'noreply@yourcompany.com',
4 subject: 'Welcome to Our Service!',
5 text: 'Welcome! Thanks for signing up.',
6 html: '<h1>Welcome!</h1><p>Thanks for signing up!</p>'
7});
8
9console.log('Email sent:', result.messageId);
Email Features
Powerful email capabilities for modern applications.
Email Templates
Create reusable templates with dynamic content and variables.
Delivery Tracking
Monitor opens, clicks, bounces, and delivery status in real-time.
Personalization
Dynamic content based on user data and behavioral patterns.
Analytics
Comprehensive email analytics and performance insights.
Basic Email Sending
Send transactional emails with rich content and tracking.
typescript
1const result = await email.send({
2 to: 'customer@example.com',
3 from: 'noreply@yourcompany.com',
4 subject: 'Welcome to Our Service!',
5
6 // Plain text version
7 text: 'Welcome! Thanks for signing up for our service.',
8
9 // HTML version
10 html: `
11 <h1>Welcome!</h1>
12 <p>Thanks for signing up for our service.</p>
13 <p>Best regards,<br>The Team</p>
14 `,
15
16 // Optional: tracking and metadata
17 metadata: {
18 userId: 'user_123',
19 campaignId: 'welcome_series'
20 }
21});
22
23console.log('Email sent:', result.messageId);
Email Templates
Create reusable templates for consistent branding and easier management.
typescript
1// First, create a template
2const template = await email.templates.create({
3 name: 'welcome-email',
4 subject: 'Welcome to {{company_name}}!',
5 html: `
6 <h1>Welcome {{first_name}}!</h1>
7 <p>Thanks for joining {{company_name}}.</p>
8 <p>Your account is now active.</p>
9 `
10});
11
12// Then use the template
13await email.send({
14 to: 'customer@example.com',
15 template: 'welcome-email',
16 data: {
17 first_name: 'John',
18 company_name: 'Acme Corp'
19 }
20});
Transactional Emails
Time-sensitive, user-triggered communications with high priority delivery.
typescript
1// Order confirmation
2await email.send({
3 to: user.email,
4 template: 'order-confirmation',
5 priority: 'high', // Ensures fast delivery
6 data: {
7 order_number: order.id,
8 total: order.total,
9 items: order.items
10 }
11});
12
13// Password reset
14await email.send({
15 to: user.email,
16 template: 'password-reset',
17 data: {
18 reset_link: generateResetLink(user.id),
19 expires_in: '24 hours'
20 }
21});
Marketing Campaigns
Promotional campaigns and newsletters with A/B testing and optimal delivery.
typescript
1// Newsletter campaign
2await email.sendCampaign({
3 template: 'monthly-newsletter',
4 segment: 'active-subscribers',
5 data: {
6 month: 'January',
7 featured_products: products,
8 special_offer: '20% off'
9 },
10
11 // Campaign settings
12 settings: {
13 sendTime: 'optimal', // Send at optimal time for each user
14 abTest: {
15 enabled: true,
16 variants: ['variant-a', 'variant-b'],
17 trafficSplit: 50
18 }
19 }
20});
Email Personalization
Use dynamic content and user data for highly personalized experiences.
typescript
1await email.send({
2 to: user.email,
3 template: 'personalized-offer',
4 data: {
5 first_name: user.firstName,
6 last_purchase: user.lastPurchase,
7 recommended_products: getRecommendations(user.id),
8 discount_percentage: calculateDiscount(user.tier)
9 }
10});
Email Attachments
Include files and inline images with your emails.
typescript
1await email.send({
2 to: 'customer@example.com',
3 subject: 'Your Invoice',
4 text: 'Please find your invoice attached.',
5
6 attachments: [
7 {
8 filename: 'invoice.pdf',
9 content: pdfBuffer,
10 contentType: 'application/pdf'
11 },
12 {
13 filename: 'logo.png',
14 path: '/path/to/logo.png',
15 cid: 'logo' // For inline images
16 }
17 ]
18});
Email Analytics & Tracking
Monitor email performance with detailed analytics and engagement metrics.
typescript
1// Enable tracking
2await email.send({
3 to: 'customer@example.com',
4 subject: 'Check out our new products',
5 html: emailContent,
6
7 tracking: {
8 opens: true,
9 clicks: true,
10 unsubscribes: true
11 }
12});
13
14// Get email analytics
15const analytics = await email.analytics.get('message-id');
16console.log('Opens:', analytics.opens);
17console.log('Clicks:', analytics.clicks);
18console.log('Delivery status:', analytics.status);
Error Handling: Always implement proper error handling for email delivery failures, invalid addresses, and quota limits.
Error Handling
Handle bounces, complaints, and delivery failures gracefully.
typescript
1try {
2 await email.send(emailConfig);
3} catch (error) {
4 if (error.code === 'INVALID_EMAIL') {
5 console.log('Invalid email address');
6 } else if (error.code === 'BLACKLISTED') {
7 console.log('Email address is blacklisted');
8 } else if (error.code === 'QUOTA_EXCEEDED') {
9 console.log('Daily sending quota exceeded');
10 } else {
11 console.log('Unexpected error:', error.message);
12 }
13}
Next Steps
Master advanced email features and build sophisticated email workflows.
Advanced Email Sending
Complex sending patterns and configurations
Template Management
Create and manage email templates
Email Analytics & Tracking
Deep dive into email performance metrics
List Management
Subscriber management and segmentation
Webhooks
Real-time email event notifications
Push Notifications
Multi-channel messaging strategy