---
title: "Create IMAP/POP Monitor"
description: "Creates a new IMAP/POP monitor."
---

`POST /api/imap-pop-monitors`

## Authentication

Requires a valid session.

- Header: `Authorization: Bearer <token>`

## Request Body

```json
{
  "customerId": "11111111-1111-4111-8111-111111111111",
  "name": "Mailbox Access",
  "hostname": "mail.deinkunde.com",
  "port": 993,
  "status": "active",
  "checkInterval": 30,
  "timeoutSeconds": 30,
  "imapPopConfig": {
    "protocol": "imap",
    "user": "monitor@deinkunde.com",
    "password": "password",
    "tls": true,
    "tlsOptions": { "rejectUnauthorized": true }
  }
}
```

### Fields

- `customerId` (number | string, required)
  - Accepts either the internal numeric customer ID or the public customer UUID.
- `name` (string, required)
- `hostname` (string, required)
  - Must be a hostname only (no protocol like `https://`, no path like `/imap`).
- `port` (number | null, optional)
  - If omitted or `null`, the worker chooses a default port depending on `imapPopConfig.protocol` and `imapPopConfig.tls`.
- `status` (string, optional)
  - Allowed: `active`, `maintenance`, `disabled`, `paused`, `inactive`
  - Note: `paused` / `inactive` are normalized to `disabled`.
- `checkInterval` (number, optional)
- `timeoutSeconds` (number, optional)
- `checkMode` (string, optional)
  - Allowed: `protocol`, `tcp`. Defaults to `protocol`.
  - In `tcp` mode the monitor performs a bare TCP port-reachability check: `imapPopConfig` is not required and is not stored. In `protocol` mode the full IMAP/POP login check runs (existing behavior).
  - **`port` is required when `checkMode` is `tcp`**. Without it the request fails with `400` / `data.code: "portRequiredForTcp"`.
- `imapPopConfig` (object, optional)
  - Stored as the monitor's `config` JSON.
  - Required (`user` + `password`) unless `checkMode` is `tcp`.

### `imapPopConfig` (worker-supported keys)

- `protocol` (`imap` | `pop3`)
  - Default: `imap`
- `user` (string)
- `password` (string)
- `tls` (boolean)
  - Default: `false`
- `tlsOptions.rejectUnauthorized` (boolean)
  - Used by the IMAP worker library; POP3 currently ignores this option.

### Default ports (worker behavior)

If `port` is omitted or `null`:

- IMAP:
  - TLS (`tls: true`): `993`
  - Non-TLS (`tls: false`): `143`
- POP3:
  - TLS (`tls: true`): `995`
  - Non-TLS (`tls: false`): `110`

## cURL

```bash
curl -X POST "https://YOUR_DOMAIN/api/imap-pop-monitors" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "customerId": "11111111-1111-4111-8111-111111111111",
    "name": "Mailbox Access",
    "hostname": "mail.deinkunde.com",
    "port": 993,
    "status": "active",
    "checkInterval": 30,
    "timeoutSeconds": 30,
    "imapPopConfig": { "protocol": "imap", "user": "monitor@deinkunde.com", "password": "password", "tls": true }
  }'
```

## Response

```json
{
  "id": 500,
  "organizationId": 1,
  "customerId": 10,
  "name": "Mailbox Access",
  "hostname": "mail.deinkunde.com",
  "port": 993,
  "checkInterval": 30,
  "timeoutSeconds": 30,
  "status": "active",
  "notificationPhoneNumber": null,
  "notificationEmail": null,
  "lastCheckedAt": null,
  "createdAt": "2026-02-26T12:00:00.000Z",
  "updatedAt": "2026-02-26T12:00:00.000Z",
  "config": {
    "protocol": "imap",
    "user": "monitor@deinkunde.com",
    "password": "password",
    "tls": true
  },
  "imapPopConfig": {
    "protocol": "imap",
    "user": "monitor@deinkunde.com",
    "password": "password",
    "tls": true
  }
}
```

## Errors

- `400` Invalid hostname or invalid request body
- `400` Invalid Customer identifier
- `401` Unauthorized
- `403` Forbidden (e.g. `readonly` or global supporter)
- `404` Customer not found

