Docs

Sending Emails

Send emails programmatically with support for HTML, text, attachments, and custom headers

Sending Emails

Send emails through the API with full support for HTML content, attachments, CC/BCC recipients, and custom headers.

Endpoint

POST /api/email/send

Authentication

Required: Bearer token in Authorization header

Authorization: Bearer YOUR_API_KEY

Request Body

FieldTypeRequiredDescription
fromstringYesSender email address
tostring/arrayYesRecipient email address(es)
ccstring/arrayNoCC recipient(s)
bccstring/arrayNoBCC recipient(s)
subjectstringYesEmail subject line
textstringNoPlain text body (required if no html)
htmlstringNoHTML body (required if no text)
attachmentsarrayNoArray of attachment objects
replyTostringNoReply-to email address
headersobjectNoCustom email headers

Request Examples

Basic Text Email

curl -X POST https://api.yourdomain.com/api/email/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "sender@example.com",
    "to": "recipient@example.com",
    "subject": "Hello World",
    "text": "This is a plain text email."
  }'

HTML Email with Multiple Recipients

curl -X POST https://api.yourdomain.com/api/email/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "noreply@yourdomain.com",
    "to": ["user1@example.com", "user2@example.com"],
    "cc": "manager@example.com",
    "subject": "Welcome to Our Service",
    "html": "<h1>Welcome!</h1><p>Thanks for joining us.</p>",
    "replyTo": "support@yourdomain.com"
  }'

Email with Attachments

curl -X POST https://api.yourdomain.com/api/email/send \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "sender@example.com",
    "to": "recipient@example.com",
    "subject": "Document Attached",
    "text": "Please find the document attached.",
    "attachments": [
      {
        "filename": "document.pdf",
        "content": "base64encodedcontent...",
        "contentType": "application/pdf"
      }
    ]
  }'

Response

Success Response (200 OK)

{
  "success": true,
  "data": {
    "messageId": "msg_1234567890abcdef",
    "status": "queued",
    "to": ["recipient@example.com"],
    "subject": "Hello World"
  },
  "message": "Email queued for delivery"
}

Error Response (400 Bad Request)

{
  "success": false,
  "error": {
    "code": "INVALID_EMAIL",
    "message": "Invalid email address format",
    "field": "to"
  }
}

Attachment Object

FieldTypeRequiredDescription
filenamestringYesName of the file
contentstringYesBase64-encoded file content
contentTypestringNoMIME type (auto-detected if not provided)

Rate Limits

  • Free tier: 100 emails/day
  • Pro tier: 10,000 emails/day
  • Enterprise: Custom limits

Webhook Events

The following events are triggered when sending emails:

  • email.sent - Email successfully sent
  • email.delivered - Email delivered to recipient
  • email.bounced - Email bounced
  • email.complaint - Spam complaint received

Best Practices

  1. Always provide both text and HTML versions for better deliverability
  2. Validate email addresses before sending to reduce bounces
  3. Use reply-to for transactional emails to manage responses
  4. Keep attachments under 25MB total per email
  5. Implement retry logic for 5xx errors

Code Examples

JavaScript/TypeScript

const response = await fetch('https://api.yourdomain.com/api/email/send', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    from: 'sender@example.com',
    to: 'recipient@example.com',
    subject: 'Hello',
    text: 'Hello World',
    html: '<p>Hello World</p>'
  })
});

const result = await response.json();

Python

import requests

response = requests.post(
    'https://api.yourdomain.com/api/email/send',
    headers={'Authorization': 'Bearer YOUR_API_KEY'},
    json={
        'from': 'sender@example.com',
        'to': 'recipient@example.com',
        'subject': 'Hello',
        'text': 'Hello World',
        'html': '<p>Hello World</p>'
    }
)

result = response.json()

On this page