Email Sending
Email Sending
Section titled “Email Sending”mailiam provides a powerful API for sending transactional and marketing emails. Built on AWS SES with global infrastructure, it delivers emails quickly and reliably to any destination.
Quick Start
Section titled “Quick Start”1. Get API Access
Section titled “1. Get API Access”Create an API key:
curl -X POST https://api.mailiam.dev/auth/keys \ -H "Authorization: Bearer your-token" \ -d '{ "name": "Production App", "permissions": ["email.send"] }'2. Send Your First Email
Section titled “2. Send Your First Email”curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "customer@example.com", "subject": "Welcome to our service!", "text": "Thanks for signing up!", "html": "<h1>Welcome!</h1><p>Thanks for signing up!</p>" }'Response:
{ "success": true, "messageId": "msg_abc123", "status": "queued"}That’s it! Your email is now being delivered.
Sending Methods
Section titled “Sending Methods”Simple Email
Section titled “Simple Email”Send a basic text/HTML email:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "user@example.com", "subject": "Account Update", "text": "Your account has been updated successfully.", "html": "<p>Your account has been <strong>updated</strong> successfully.</p>", "from": "noreply@yourdomain.com" }'Multiple Recipients
Section titled “Multiple Recipients”Send to multiple recipients:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": ["user1@example.com", "user2@example.com"], "cc": ["manager@company.com"], "bcc": ["archive@company.com"], "subject": "Team Update", "html": "<p>Here is the weekly team update...</p>" }'Email with Attachments
Section titled “Email with Attachments”Send emails with file attachments:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -F "to=customer@example.com" \ -F "subject=Your Invoice" \ -F "html=<p>Please find your invoice attached.</p>" \ -F "attachments=@/path/to/invoice.pdf" \ -F "attachments=@/path/to/receipt.png"Templated Emails
Section titled “Templated Emails”Use email templates with variables:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "user@example.com", "template": "welcome-email", "variables": { "firstName": "John", "companyName": "Acme Corp", "activationLink": "https://app.com/activate?token=abc123" } }'Advanced Features
Section titled “Advanced Features”Custom Headers
Section titled “Custom Headers”Add custom email headers:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "user@example.com", "subject": "Order Confirmation", "html": "<p>Your order has been confirmed.</p>", "headers": { "X-Order-ID": "12345", "X-Customer-Type": "premium", "Reply-To": "support@company.com" } }'Scheduled Sending
Section titled “Scheduled Sending”Schedule emails for future delivery:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "user@example.com", "subject": "Reminder: Meeting Tomorrow", "html": "<p>Don`t forget about our meeting tomorrow at 2 PM.</p>", "scheduleFor": "2024-01-15T14:00:00Z" }'Priority Sending
Section titled “Priority Sending”Set email priority for urgent messages:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "admin@company.com", "subject": "URGENT: Server Alert", "text": "Server is experiencing high CPU usage", "priority": "high" }'Tracking Options
Section titled “Tracking Options”Enable email tracking:
curl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "to": "customer@example.com", "subject": "Product Newsletter", "html": "<p>Check out our latest products...</p>", "tracking": { "opens": true, "clicks": true, "unsubscribe": true } }'Email Templates
Section titled “Email Templates”Creating Templates
Section titled “Creating Templates”Create reusable email templates:
curl -X POST https://api.mailiam.dev/email/templates \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "name": "welcome-email", "subject": "Welcome to {{companyName}}!", "html": "<h1>Welcome {{firstName}}!</h1><p>Thanks for joining {{companyName}}.</p><a href=\"{{activationLink}}\">Activate your account</a>", "text": "Welcome {{firstName}}! Thanks for joining {{companyName}}. Activate your account: {{activationLink}}" }'Template Variables
Section titled “Template Variables”Supported variable types:
- Text:
{{firstName}},{{companyName}} - URLs:
{{activationLink}},{{unsubscribeUrl}} - Conditionals:
{{#isPremium}}Premium content{{/isPremium}} - Loops:
{{#items}}<li>{{name}}</li>{{/items}}
Template Example
Section titled “Template Example”<!DOCTYPE html><html><head> <title>{{subject}}</title></head><body> <h1>Hello {{firstName}}!</h1>
{{#isWelcome}} <p>Welcome to {{companyName}}! We're excited to have you.</p> {{/isWelcome}}
<h2>Your Recent Orders:</h2> <ul> {{#orders}} <li>{{productName}} - ${{price}}</li> {{/orders}} </ul>
<p>Best regards,<br>The {{companyName}} Team</p>
<footer> <a href="{{unsubscribeUrl}}">Unsubscribe</a> </footer></body></html>Bulk Email Operations
Section titled “Bulk Email Operations”Batch Sending
Section titled “Batch Sending”Send emails to multiple recipients efficiently:
curl -X POST https://api.mailiam.dev/email/batch \ -H "Authorization: Bearer your-api-key" \ -H "Content-Type: application/json" \ -d '{ "template": "newsletter", "recipients": [ { "email": "user1@example.com", "variables": {"firstName": "John", "plan": "premium"} }, { "email": "user2@example.com", "variables": {"firstName": "Jane", "plan": "basic"} } ] }'Mailing Lists
Section titled “Mailing Lists”Create and manage mailing lists:
# Create listcurl -X POST https://api.mailiam.dev/email/lists \ -H "Authorization: Bearer your-api-key" \ -d '{ "name": "Newsletter Subscribers", "description": "Weekly newsletter recipients" }'
# Add subscriberscurl -X POST https://api.mailiam.dev/email/lists/list_123/subscribers \ -H "Authorization: Bearer your-api-key" \ -d '{ "subscribers": [ {"email": "user1@example.com", "name": "John Doe"}, {"email": "user2@example.com", "name": "Jane Smith"} ] }'
# Send to listcurl -X POST https://api.mailiam.dev/email/send \ -H "Authorization: Bearer your-api-key" \ -d '{ "list": "list_123", "subject": "Weekly Newsletter", "template": "newsletter" }'Suppression Lists
Section titled “Suppression Lists”Manage unsubscribed and bounced addresses:
# Add to suppression listcurl -X POST https://api.mailiam.dev/email/suppression \ -H "Authorization: Bearer your-api-key" \ -d '{ "email": "bounced@example.com", "reason": "bounced" }'
# Check if email is suppressedcurl -H "Authorization: Bearer your-api-key" \ https://api.mailiam.dev/email/suppression/check?email=user@example.comDelivery and Analytics
Section titled “Delivery and Analytics”Email Status Tracking
Section titled “Email Status Tracking”Check email delivery status:
curl -H "Authorization: Bearer your-api-key" \ https://api.mailiam.dev/email/status/msg_abc123Response:
{ "messageId": "msg_abc123", "status": "delivered", "events": [ { "type": "queued", "timestamp": "2024-01-10T10:00:00Z" }, { "type": "sent", "timestamp": "2024-01-10T10:00:05Z" }, { "type": "delivered", "timestamp": "2024-01-10T10:00:12Z" }, { "type": "opened", "timestamp": "2024-01-10T10:15:30Z" } ]}Analytics Dashboard
Section titled “Analytics Dashboard”Get sending statistics:
curl -H "Authorization: Bearer your-api-key" \ "https://api.mailiam.dev/email/analytics?period=last_30_days"Response:
{ "period": "last_30_days", "emails_sent": 15420, "delivered": 14889, "bounced": 234, "complaints": 12, "opens": 8945, "clicks": 2134, "unsubscribes": 45, "delivery_rate": 96.5, "open_rate": 60.1, "click_rate": 23.9}Webhook Events
Section titled “Webhook Events”Receive real-time delivery events:
curl -X POST https://api.mailiam.dev/email/webhooks \ -H "Authorization: Bearer your-api-key" \ -d '{ "url": "https://your-app.com/webhook", "events": ["delivered", "bounced", "opened", "clicked"] }'Webhook payload example:
{ "type": "delivered", "messageId": "msg_abc123", "recipient": "user@example.com", "timestamp": "2024-01-10T10:00:12Z", "metadata": { "campaignId": "newsletter_jan_2024" }}Integration Examples
Section titled “Integration Examples”Node.js Integration
Section titled “Node.js Integration”const mailiam = require('@mailiam/node');
const client = new mailiam.Client({ apiKey: 'your-api-key'});
async function sendWelcomeEmail(userEmail, firstName) { try { const result = await client.email.send({ to: userEmail, template: 'welcome-email', variables: { firstName: firstName, companyName: 'Acme Corp' } });
console.log('Email sent:', result.messageId); return result; } catch (error) { console.error('Email failed:', error); throw error; }}Python Integration
Section titled “Python Integration”import mailiam
client = mailiam.Client(api_key='your-api-key')
def send_order_confirmation(email, order_data): try: result = client.email.send( to=email, subject=f"Order #{order_data['id']} Confirmed", template='order-confirmation', variables=order_data )
print(f"Email sent: {result['messageId']}") return result except mailiam.mailiamError as e: print(f"Email failed: {e}") raiseReact Hook
Section titled “React Hook”import { useState } from 'react';
function usemailiam(apiKey) { const [loading, setLoading] = useState(false); const [error, setError] = useState(null);
const sendEmail = async (emailData) => { setLoading(true); setError(null);
try { const response = await fetch('https://api.mailiam.dev/email/send', { method: 'POST', headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify(emailData) });
if (!response.ok) { throw new Error('Failed to send email'); }
const result = await response.json(); setLoading(false); return result; } catch (err) { setError(err.message); setLoading(false); throw err; } };
return { sendEmail, loading, error };}Best Practices
Section titled “Best Practices”Email Deliverability
Section titled “Email Deliverability”Sender Reputation:
- Use consistent sender addresses
- Implement SPF/DKIM authentication
- Monitor bounce and complaint rates
- Keep suppression lists updated
Content Quality:
- Write clear, relevant subject lines
- Maintain good text-to-image ratios
- Include unsubscribe links
- Avoid spam trigger words
Rate Limits and Quotas
Section titled “Rate Limits and Quotas”Default Limits:
- 200 emails per second
- 1M emails per day
- 10MB maximum email size
- 25MB maximum attachment size
Optimization:
- Use batch sending for multiple recipients
- Implement exponential backoff for retries
- Cache templates to reduce API calls
- Monitor your sending quotas
Error Handling
Section titled “Error Handling”try { const result = await client.email.send(emailData); console.log('Success:', result.messageId);} catch (error) { switch (error.code) { case 'RATE_LIMIT_EXCEEDED': // Wait and retry await sleep(60000); return retryEmail(emailData);
case 'INVALID_RECIPIENT': // Remove from mailing list await removeFromList(emailData.to); break;
case 'QUOTA_EXCEEDED': // Alert administrators await alertAdmins('Email quota exceeded'); break;
default: console.error('Unexpected error:', error); }}Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Emails not being delivered?
- Check sender reputation and authentication
- Verify recipient email addresses
- Review content for spam triggers
- Check suppression lists
High bounce rate?
- Validate email addresses before sending
- Remove invalid addresses from lists
- Use double opt-in for subscriptions
- Monitor feedback loops
Low open rates?
- Test subject lines for effectiveness
- Check sender name recognition
- Optimize send times
- Segment your audience
Getting Help
Section titled “Getting Help”- Monitor your sending with our dashboard
- Check our API Reference for detailed documentation
- Contact support at support@mailiam.dev
Security and Compliance
Section titled “Security and Compliance”Data Protection
Section titled “Data Protection”- All emails encrypted in transit (TLS 1.2+)
- API keys use secure authentication
- Personal data automatically purged
- GDPR compliant data handling
Compliance Features
Section titled “Compliance Features”- CAN-SPAM: Automatic unsubscribe handling
- GDPR: Data export and deletion tools
- CCPA: Privacy controls and transparency
- SOC 2: Security and availability standards
Next Steps
Section titled “Next Steps”- Learn about Forms for contact form integration
- Check out Email Forwarding for inbound email
- Explore our API Reference for complete documentation
- Try our SDKs and libraries for your platform