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
| Field | Type | Required | Description |
|---|---|---|---|
| to | string | Yes | Recipient email address |
| subject | string | Yes | Email subject line |
| body | string | Yes | Plain text email body |
| html | string | No | HTML email body (optional, overrides plain text rendering) |
| from_name | string | No | Sender display name (default: "SelfIAM Mailer") |
| reply_to | string | No | Reply-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
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | A 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
| Parameter | Type | Description | |
|---|---|---|---|
| id | string | Yes | The 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.
| Code | HTTP Status | Description |
|---|---|---|
| AUTH_001 | 401 | Authentication required |
| AUTH_002 | 401 | Invalid email or password |
| AUTH_003 | 409 | Email already registered |
| AUTH_004 | 401 | Invalid or expired session |
| AUTH_005 | 403 | Forbidden: insufficient permissions |
| VAL_001 | 400 | Validation failed |
| VAL_002 | 400 | Missing required field |
| VAL_003 | 400 | Invalid email format |
| KEY_001 | 401 | Invalid API key |
| KEY_002 | 400 | Maximum active keys reached |
| KEY_003 | 404 | API key not found |
| RATE_001 | 429 | Rate limit exceeded |
| USR_001 | 404 | User not found |
| USR_002 | 400 | Cannot delete super admin |
| SRV_001 | 500 | Internal server error |
| SRV_002 | 500 | Email delivery failed |
| SRV_003 | 503 | Database 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
| Header | Description |
|---|---|
| X-RateLimit-Limit | Maximum requests allowed per day |
| X-RateLimit-Remaining | Number of requests remaining in the current window |
| X-RateLimit-Reset | ISO 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.