Get started

Authentication

MailAfrica supports JWT bearer tokens for account operations and API keys for programmatic integrations. Both are account-scoped — you only ever access your own data.

MailAfrica supports two authentication methods depending on what you're doing. Every protected request is scoped to your account — credentials can never reach another user's data or any internal platform surface.

API keys (recommended)

Use API keys for server-to-server integrations: sending email, reading messages, configuring sender IDs and webhooks, and checking balance. They are independent of your password and can be revoked per key.

Send a key in any of these formats — all are equivalent:

MethodHeader
API key headerX-API-Key: MAIL_...
BearerAuthorization: Bearer MAIL_...
RawAuthorization: MAIL_...
bash
curl https://api.mailafrica.online/api/billing/balance \
  -H "X-API-Key: MAIL_abcd1234..."
Treat keys like passwords. The plaintext is shown once at creation. Rotate by revoking the old key and issuing a new one — see API Keys.

JWT bearer tokens

JWTs are issued by register and login and are used for account management: updating your profile, verifying email/phone, and managing API keys themselves.

Authorization: Bearer <your_jwt_token>

Log in

bash
curl -X POST https://api.mailafrica.online/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "identifier": "developer@example.com",
    "password": "your-password"
  }'

identifier is your email if it contains @, otherwise your Tanzanian phone number (+255...). The response contains token, refresh_token, and user. Access tokens expire after 60 minutes; refresh tokens are single-use and rotated.

bash
curl -X POST https://api.mailafrica.online/api/auth/refresh \
  -H "Content-Type: application/json" \
  -d '{"refresh_token": "<your_refresh_token>"}'

Unauthenticated endpoints

A small set of endpoints need no credentials because they are part of account onboarding:

  • POST /api/auth/register, POST /api/auth/login, POST /api/auth/google.
  • POST /api/auth/email/verify — verification links are signed and single-use.

When you'll be blocked

StatusCodeWhy
401UNAUTHORIZEDMissing, malformed, or expired credentials.
403ACCOUNT_DISABLEDYour account was disabled; existing keys stop working immediately.
403FORBIDDENVerified identity required (email or phone) for this operation.