API Documentation

Last updated: August 19, 2026

Getting Started

The SelfIAM Mailer API is a RESTful service for sending emails and managing API keys. All requests and responses use JSON.

Base URL

https://mailer.selfiam.site/api/v1

Authentication

All API requests require a valid API key sent as a Bearer token in the Authorization header. You can create and manage API keys from the dashboard.

Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxx

Requests without a valid token will receive a 401 Unauthorized response with the error code AUTH_001.

POST /api/v1/send

Sends an email. This is the primary endpoint of the Service.

Request Body

FieldTypeRequiredDescription
tostringYesRecipient email address
subjectstringYesEmail subject line
bodystringYesPlain text email body
htmlstringNoHTML email body (optional, overrides plain text rendering)
from_namestringNoSender display name (default: "SelfIAM Mailer")
reply_tostringNoReply-To email address

Example Request

curl -X POST https://mailer.selfiam.site/api/v1/send \
  -H "Authorization: Bearer sk_xxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "recipient@example.com",
    "subject": "Hello from SelfIAM Mailer",
    "body": "This is a test email sent via the API.",
    "from_name": "My App"
  }'

Success Response200 OK

{
  "success": true,
  "emailId": "re_xxxxxxxxxxxx",
  "remaining": 24,
  "reset": "2026-08-20T00:00:00.000Z"
}

Error Response400 / 401 / 429 / 500

{
  "success": false,
  "error": "Validation failed",
  "code": "VAL_001",
  "details": {
    "fieldErrors": {
      "to": ["Invalid email"]
    }
  }
}

GET /api/v1/keys

Lists all API keys associated with the authenticated user. Returns key metadata only — raw keys are never returned.

Requires session-based authentication.

Example Request

curl https://mailer.selfiam.site/api/v1/keys \
  -H "Authorization: Bearer session_token"

Response200 OK

{
  "success": true,
  "keys": [
    {
      "_id": "64a1b2c3d4e5f6a7b8c9d0e1",
      "key_prefix": "sk_a1b2",
      "name": "Production",
      "is_active": true,
      "created_at": "2026-08-15T10:30:00.000Z"
    }
  ]
}

POST /api/v1/keys

Creates a new API key. The raw key is returned exactly once in the response. Store it securely — it cannot be retrieved later.

Requires session-based authentication. Subject to max active keys limit per user.

Request Body

FieldTypeRequiredDescription
namestringYesA human-readable label for the key

Example Request

curl -X POST https://mailer.selfiam.site/api/v1/keys \
  -H "Content-Type: application/json" \
  -d '{ "name": "Production" }'

Response201 Created

{
  "success": true,
  "rawKey": "sk_a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
  "name": "Production"
}

DELETE /api/v1/keys/[id]

Revokes (deactivates) an API key. The key will immediately stop working for all future requests.

Requires session-based authentication. You can only revoke your own keys.

Path Parameters

ParameterTypeDescription
idstringYesThe MongoDB ObjectId of the API key

Example Request

curl -X DELETE https://mailer.selfiam.site/api/v1/keys/64a1b2c3d4e5f6a7b8c9d0e1

Response200 OK

{
  "success": true
}

GET /api/v1/emails

Lists the most recent emails sent through the authenticated user's API keys. Returns up to 100 entries sorted by creation date (newest first).

Requires session-based authentication.

Example Request

curl https://mailer.selfiam.site/api/v1/emails

Response200 OK

{
  "success": true,
  "emails": [
    {
      "_id": "64a1b2c3d4e5f6a7b8c9d0e2",
      "to": "recipient@example.com",
      "from_name": "My App",
      "subject": "Hello from SelfIAM Mailer",
      "status": "sent",
      "created_at": "2026-08-19T14:22:00.000Z",
      "body": "This is a test email sent via the API.",
      "html": "<p>This is a test email sent via the API.</p>"
    }
  ]
}

Error Codes

All error responses include a code field for programmatic handling.

CodeHTTP StatusDescription
AUTH_001401Authentication required
AUTH_002401Invalid email or password
AUTH_003409Email already registered
AUTH_004401Invalid or expired session
AUTH_005403Forbidden: insufficient permissions
VAL_001400Validation failed
VAL_002400Missing required field
VAL_003400Invalid email format
KEY_001401Invalid API key
KEY_002400Maximum active keys reached
KEY_003404API key not found
RATE_001429Rate limit exceeded
USR_001404User not found
USR_002400Cannot delete super admin
SRV_001500Internal server error
SRV_002500Email delivery failed
SRV_003503Database connection failed

Rate Limiting

The POST /api/v1/send endpoint is subject to a daily rate limit. The default limit is 25 requests per day per user. The limit resets at midnight UTC.

Response Headers

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per day
X-RateLimit-RemainingNumber of requests remaining in the current window
X-RateLimit-ResetISO 8601 timestamp when the rate limit resets

Example

HTTP/1.1 200 OK
X-RateLimit-Limit: 25
X-RateLimit-Remaining: 24
X-RateLimit-Reset: 2026-08-20T00:00:00.000Z

When you exceed the rate limit, the API returns 429 Too Many Requests with error code RATE_001. Wait until the reset time before retrying.