Outbound email

Templates

Create and manage reusable email templates with {{variable}} placeholders, then send with a template_id and variables.

Templates keep subject lines and HTML consistent. Store them once, render them per send with variables — perfect for OTPs, receipts, and notifications.

Create a template

bash
curl -X POST https://api.mailafrica.online/api/outbound/templates \
  -H "X-API-Key: MAIL_<your_api_key_here>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "otp",
    "subject": "Your verification code: {{code}}",
    "html_body": "<p>Hi {{name}}, your code is <strong>{{code}}</strong>.</p>",
    "text_body": "Hi {{name}}, your verification code is {{code}}."
  }'

Placeholders use {{key}} and are rendered from the variables map you pass at send time. Unknown keys render as empty strings.

Send with a template

bash
curl -X POST https://api.mailafrica.online/api/outbound/emails \
  -H "X-API-Key: MAIL_<your_api_key_here>" \
  -H "Content-Type: application/json" \
  -d '{
    "to": ["user@example.com"],
    "template_id": 5,
    "variables": { "name": "Grace", "code": "482913" }
  }'

Manage templates

bash
# List templates
curl https://api.mailafrica.online/api/outbound/templates \
  -H "X-API-Key: MAIL_<your_api_key_here>"

# Update (full replace)
curl -X PATCH https://api.mailafrica.online/api/outbound/templates/5 \
  -H "X-API-Key: MAIL_<your_api_key_here>" \
  -H "Content-Type: application/json" \
  -d '{"name": "otp-v2", "subject": "Your code: {{code}}", "text_body": "Code: {{code}}"}'

# Delete
curl -X DELETE https://api.mailafrica.online/api/outbound/templates/5 \
  -H "X-API-Key: MAIL_<your_api_key_here>"

PATCH replaces the whole template (all fields), so send the complete definition. Deleting returns {"deleted_template_id": 5}.