Accounts API
The Accounts API allows you to programmatically manage email accounts in EmailEngine. You can register new accounts, update settings, monitor connection status, and handle OAuth2 authentication.
Overview
Email accounts are the core resource in EmailEngine. Each account represents a connection to an email service (Gmail, Outlook, IMAP/SMTP server) and maintains:
- Connection credentials (OAuth2 tokens or passwords)
- Mailbox synchronization state
- Account-specific settings
- Connection status and health
Account Object Structure
{
"account": "user@example.com",
"name": "John Doe",
"email": "user@example.com",
"state": "connected",
"syncTime": "2025-01-15T10:30:00.000Z",
"notifyFrom": "2025-01-01T00:00:00.000Z",
"lastError": null,
"authFailureDisabledAt": null,
"imap": {
"host": "imap.gmail.com",
"port": 993,
"secure": true,
"disabled": false
},
"smtp": {
"host": "smtp.gmail.com",
"port": 465,
"secure": true,
"disabled": false
},
"type": "gmail",
"oauth2": {
"provider": "AAABhaBPHscAAAAH",
"auth": {
"user": "user@example.com"
}
}
}
The state field reports where the connection stands. See Account States for the full list and what each one means for your application. authFailureDisabledAt is null unless EmailEngine itself switched syncing off after repeated authentication failures, see Accounts switched off automatically.
Common Operations
1. Register Account
Register a new email account with EmailEngine.
Endpoint: POST /v1/account
Request Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
account | string | Yes | Unique account identifier (usually email address) |
name | string | Yes | Display name for the account |
email | string | No | Email address (defaults to account) |
imap | object | No | IMAP connection settings |
smtp | object | No | SMTP connection settings |
oauth2 | object | No | OAuth2 settings |
notifyFrom | string | No | ISO date to send webhooks from (default: account creation time) |
Only account and name are required by the schema. In practice, provide either imap (usually together with smtp) or oauth2 so the account can actually connect to a mail server.
IMAP Configuration:
{
"host": "imap.example.com",
"port": 993,
"secure": true,
"auth": {
"user": "username",
"pass": "password"
}
}
SMTP Configuration:
{
"host": "smtp.example.com",
"port": 465,
"secure": true,
"auth": {
"user": "username",
"pass": "password"
}
}
Examples:
- cURL
- Python
curl -X POST https://emailengine.example.com/v1/account \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"account": "user@example.com",
"name": "John Doe",
"imap": {
"host": "imap.example.com",
"port": 993,
"secure": true,
"auth": {
"user": "user@example.com",
"pass": "password"
}
}
}'
import requests
response = requests.post(
'https://emailengine.example.com/v1/account',
headers={
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
json={
'account': 'user@example.com',
'name': 'John Doe',
'imap': {
'host': 'imap.example.com',
'port': 993,
'secure': True,
'auth': {
'user': 'user@example.com',
'pass': 'password'
}
}
}
)
result = response.json()
print(f"Account registered: {result['account']}")
Response:
{
"account": "user@example.com",
"state": "new"
}
The state field in this response indicates whether the account was created (new) or an existing account with the same ID was updated (existing). Credentials are not verified while handling this request: the account connects afterwards, and a bad password surfaces as the authenticationError state rather than as an error here.
Use Cases:
- Onboarding new users to your application
- Allowing users to connect multiple email accounts
- Automated account provisioning in bulk
2. List Accounts
Retrieve all registered accounts.
Endpoint: GET /v1/accounts
Query Parameters:
| Parameter | Type | Description |
|---|---|---|
page | number | Page number (0-indexed, default 0) |
pageSize | number | Items per page (default 20) |
state | string | Filter by account state |
query | string | Filter accounts by string match |
Each entry carries a subset of the account object: account, name, email, type, app, state, webhooks, proxy, smtpEhloName, counters, syncTime, authFailureDisabledAt, lastError and, for delegated accounts, delegationError.
Examples:
curl "https://emailengine.example.com/v1/accounts?pageSize=50" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response:
{
"total": 2,
"page": 0,
"pages": 1,
"accounts": [
{
"account": "user1@example.com",
"name": "John Doe",
"email": "user1@example.com",
"state": "connected"
},
{
"account": "user2@example.com",
"name": "Jane Smith",
"email": "user2@example.com",
"state": "authenticationError"
}
]
}
Use Cases:
- Dashboard displaying all connected accounts
- Health monitoring across accounts
- Bulk operations on multiple accounts
3. Get Account Details
Retrieve detailed information about a specific account.
Endpoint: GET /v1/account/:account
Path Parameters:
| Parameter | Description |
|---|---|
account | Account identifier |
Examples:
curl "https://emailengine.example.com/v1/account/user@example.com" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response:
{
"account": "user@example.com",
"name": "John Doe",
"email": "user@example.com",
"state": "connected",
"syncTime": "2025-01-15T10:30:00.000Z",
"lastError": null,
"counters": {
"events": {
"messageNew": 30,
"messageDeleted": 5
}
}
}
Use Cases:
- Displaying account status in user interface
- Checking connection health
- Retrieving account statistics