Skip to main content

Email API

Enterprise-grade email delivery with 99.9% deliverability, drag-and-drop templates, real-time analytics, and full SMTP/API support.

🚀 Quick Start​

curl -X POST https://api.afriroute.ai/api/v1/email/send \
-H "Authorization: Bearer $AFRIROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Welcome to AfriRoute",
"html": "<h1>Welcome!</h1><p>Thanks for signing up.</p>"
}'

📧 Send Email​

Simple Email​

POST /v1/email/send
const response = await fetch('https://api.afriroute.ai/api/v1/email/send', {
method: 'POST',
headers: {
'Authorization': 'Bearer $AFRIROUTE_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: '[email protected]',
to: '[email protected]',
subject: 'Order Confirmation #12345',
html: `
<h2>Thank you for your order!</h2>
<p>Order #12345 has been confirmed.</p>
<a href="https://yourapp.com/orders/12345">View Order</a>
`
})
});

const data = await response.json();
console.log(data.message_id); // email_abc123

With Attachments​

{
from: '[email protected]',
to: '[email protected]',
subject: 'Invoice #12345',
html: '<p>Please find your invoice attached.</p>',
attachments: [
{
filename: 'invoice-12345.pdf',
content: 'base64_encoded_content',
contentType: 'application/pdf'
}
]
}

With CC/BCC​

{
from: '[email protected]',
to: '[email protected]',
cc: ['[email protected]'],
bcc: ['[email protected]'],
subject: 'Proposal for Review',
html: '<p>Please review the attached proposal.</p>'
}

📨 Templates​

Create reusable email templates with variables.

Create Template​

curl -X POST https://api.afriroute.ai/api/v1/email/templates \
-H "Authorization: Bearer $AFRIROUTE_API_KEY" \
-d '{
"name": "order_confirmation",
"subject": "Order {{order_id}} Confirmed",
"html": "<h2>Hi {{customer_name}},</h2><p>Your order {{order_id}} has been confirmed!</p>"
}'

Send Using Template​

await fetch('https://api.afriroute.ai/api/v1/email/send', {
method: 'POST',
headers: {
'Authorization': 'Bearer $AFRIROUTE_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: '[email protected]',
to: '[email protected]',
template: 'order_confirmation',
variables: {
customer_name: 'John Doe',
order_id: '#12345'
}
})
});

📬 Bulk Email​

Send to multiple recipients efficiently.

await fetch('https://api.afriroute.ai/api/v1/email/bulk', {
method: 'POST',
headers: {
'Authorization': 'Bearer $AFRIROUTE_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
from: '[email protected]',
subject: 'Monthly Newsletter - March 2024',
html: '<h1>This month in tech...</h1>',
recipients: [
{ email: '[email protected]', name: 'Alice' },
{ email: '[email protected]', name: 'Bob' },
{ email: '[email protected]', name: 'Charlie' }
],
batch_size: 100
})
});

🎨 HTML Templates​

Responsive Template​

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.button {
background: #0066FF;
color: white;
padding: 12px 24px;
text-decoration: none;
border-radius: 4px;
display: inline-block;
}
@media (max-width: 600px) {
.container { padding: 10px; }
}
</style>
</head>
<body>
<div class="container">
<h2>Hi {{customer_name}},</h2>
<p>Your order {{order_id}} has been confirmed and will ship soon.</p>
<a href="{{tracking_url}}" class="button">Track Order</a>
</div>
</body>
</html>

🔔 Webhooks​

Track email events in real-time.

app.post('/webhooks/email', (req, res) => {
const { event, email, message_id, timestamp } = req.body;

switch (event) {
case 'delivered':
console.log(`Email ${message_id} delivered to ${email}`);
break;
case 'opened':
console.log(`Email ${message_id} opened by ${email}`);
break;
case 'clicked':
console.log(`Link clicked in ${message_id} by ${email}`);
break;
case 'bounced':
console.log(`Email ${message_id} bounced: ${req.body.reason}`);
break;
case 'spam':
console.log(`Email ${message_id} marked as spam by ${email}`);
break;
case 'unsubscribed':
console.log(`${email} unsubscribed`);
await removeFromMailingList(email);
break;
}

res.sendStatus(200);
});

Event Types​

EventDescription
sentEmail sent to provider
deliveredEmail delivered to inbox
openedRecipient opened email
clickedRecipient clicked link
bouncedEmail bounced (hard/soft)
spamMarked as spam
unsubscribedRecipient unsubscribed

📊 Analytics​

// Get email stats
const stats = await fetch('https://api.afriroute.ai/api/v1/email/analytics', {
headers: { 'Authorization': 'Bearer $AFRIROUTE_API_KEY' }
});

const data = await stats.json();
console.log(data);
// {
// sent: 10000,
// delivered: 9950,
// opened: 3500,
// clicked: 800,
// bounced: 50,
// deliverability_rate: 99.5,
// open_rate: 35.2,
// click_rate: 8.0
// }

🔒 Authentication​

SMTP Credentials​

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransporter({
host: 'smtp.afriroute.ai',
port: 587,
secure: false, // STARTTLS
auth: {
user: 'your_smtp_username',
pass: 'your_smtp_password'
}
});

await transporter.sendMail({
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
html: '<p>Hello from SMTP!</p>'
});

API Key​

fetch('https://api.afriroute.ai/api/v1/email/send', {
headers: {
'Authorization': 'Bearer $AFRIROUTE_API_KEY'
}
});

🛡️ Deliverability​

SPF Record​

v=spf1 include:spf.afriroute.ai ~all

DKIM​

Automatically signed by AfriRoute servers.

DMARC​

v=DMARC1; p=quarantine; rua=mailto:[email protected]

Custom Domain​

# Verify domain ownership
curl -X POST https://api.afriroute.ai/api/v1/email/domains \
-H "Authorization: Bearer $AFRIROUTE_API_KEY" \
-d '{"domain": "yourcompany.com"}'

# Add DNS records shown in response
# TXT record: afriroute-verification=abc123xyz
# CNAME record: em.yourcompany.com → mail.afriroute.ai

💡 Best Practices​

Content​

  • Write compelling subject lines - 50 characters or less
  • Include plain text version - for accessibility and spam filters
  • Optimize for mobile - 60% of emails opened on mobile
  • Use clear CTAs - one primary action per email
  • Test before sending - use test mode for previews

Deliverability​

  • Warm up new domains - start with 100 emails/day, increase gradually
  • Clean your lists regularly - remove bounces and inactive users
  • Monitor engagement rates - open rate >20%, click rate >2%
  • Authenticate your domain - SPF, DKIM, DMARC
  • Avoid spam triggers - excessive caps, too many links, spam words

Compliance​

  • Include unsubscribe link - required by law (CAN-SPAM, GDPR)
  • Add physical address - in email footer
  • Honor opt-outs immediately - within 24 hours
  • Get explicit consent - for marketing emails
  • Keep records - of consent and opt-outs

Performance​

  • Use templates - for consistent branding
  • Batch large sends - 100-500 per batch
  • Implement retry logic - for failed sends
  • Cache rendered templates - reduce processing time

⚠️ Error Handling​

try {
await sendEmail(emailData);
} catch (error) {
if (error.code === 'INVALID_EMAIL') {
console.error('Invalid recipient email address');
} else if (error.code === 'DOMAIN_NOT_VERIFIED') {
console.error('Please verify your sending domain first');
} else if (error.code === 'RATE_LIMIT_EXCEEDED') {
console.error('Too many emails sent. Please slow down.');
}
}

💰 Pricing​

PlanPriceEmails/MonthFeatures
Starter$1010,000Basic analytics
Pro$50100,000Advanced analytics, templates
EnterpriseCustomUnlimitedDedicated IP, priority support

Overage: $0.001 per email

View detailed pricing →

📊 Dashboard Features​

  • 📈 Real-time analytics
  • 📧 Template builder (drag & drop)
  • 📋 List management
  • 🔍 Search & filter emails
  • 📊 A/B testing
  • 🎯 Segmentation
  • 📅 Scheduled sends

🛠️ SDKs​

// JavaScript/Node.js
const afriroute = require('@afriroute/sdk');
const email = new afriroute.Email('$AFRIROUTE_API_KEY');

await email.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome to our service!</h1>'
});
# Python
from afriroute import Email

email = Email(api_key='$AFRIROUTE_API_KEY')
email.send(
from_='[email protected]',
to='[email protected]',
subject='Welcome!',
html='<h1>Welcome to our service!</h1>'
)

Need help? Contact Support → | View Code Examples →