📧 Email API Service

Email sending service powered by Mailgun

🚀 Endpoints

GET /api/health

Check service health and configuration

POST /api/email/send

Send single email or to multiple recipients

Request Format
{
  "to": "user@example.com", // or ["user1@example.com", "user2@example.com"]
  "subject": "Email Subject",
  "html": "<h1>HTML Content</h1>",
  "text": "Plain text content", // optional if html provided
  "from": "noreply@yourdomain.com", // optional
  "replyTo": "reply@yourdomain.com", // optional
  "cc": ["cc@example.com"], // optional
  "bcc": ["bcc@example.com"], // optional
  "tags": ["campaign", "newsletter"], // optional
  "variables": {"name": "John"} // optional
}

POST /api/email/bulk

Send bulk emails with personalization

Request Format
{
  "recipients": [
    { "email": "user1@example.com", "variables": {"name": "John"} },
    { "email": "user2@example.com", "variables": {"name": "Jane"} }
  ],
  "subject": "Hello %recipient.name%",
  "html": "<h1>Hello %recipient.name%</h1>",
  "text": "Hello %recipient.name%",
  "from": "noreply@yourdomain.com", // optional
  "tags": ["bulk", "campaign"] // optional
}

🔐 Authentication

All API endpoints require Bearer token authentication:

Authorization: Bearer YOUR_EMAIL_API_TOKEN

📋 Environment Variables

  • EMAIL_API_TOKEN - API authentication token
  • MAILGUN_API_KEY - Mailgun API key
  • MAILGUN_HOST - Mailgun host (optional, defaults to EU)
  • MAILGUN_DEFAULT_FROM - Default from address (optional)
  • ALLOWED_IPS - Comma-separated allowed IPs (optional)

🔧 PHP Integration Example

<?php
function sendEmailViaAPI($to, $subject, $html, $text = null) {
    $data = [
        'to' => $to,
        'subject' => $subject,
        'html' => $html,
        'text' => $text,
        'from' => 'noreply@yourdomain.com',
        'tags' => ['php-legacy']
    ];
    
    $ch = curl_init('https://email.eventjuicer.com/api/email/send');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json',
        'Authorization: Bearer ' . getenv('EMAIL_API_TOKEN')
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    return ['success' => $httpCode === 200, 'response' => json_decode($response, true)];
}
?>