> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maqetin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Send a message

> Queue one transactional email from your server with a secret key.

Send a template, a recipient and your data; Maqetin answers `202` with the message id, and the email follows. Use it for mail a person expects from an action of theirs: a receipt, a password reset, an invite.

A transactional message ignores the contact's email opt-in, never reaches a [suppressed](https://docs.maqetin.com/messaging/suppressions.md) address and has no unsubscribe link.

## Limits

| What | Limit |
| - | - |
| Body | 100 KiB |
| `data` | 16 KiB (16,384 bytes) as JSON |
| `Idempotency-Key` | Letters, digits and `_ . : -`, at most 100 characters. Remembered for 7 days. |
| Rate, per key | 300 sends a minute, and 600 requests a minute across messages and contacts |

## Headers

**Authorization** `string` *required*

`Bearer mq_sec_…`, a secret key with the `messages:send` scope. A public key is a `401`. A secret key without the scope is a `403`.

**Idempotency-Key** `string`

Send the same key on a retry and Maqetin sends the message once. See [Send a retry safely](#send-a-retry-safely).

## Body

Any top-level field that is not listed here is a `400`.

**channel** `string` *required*

`email`, the one channel built today.

**templateId** `string` *required*

The id of a [template](https://docs.maqetin.com/messaging/templates.md) in your workspace.

**to** `object` *required*

Exactly one of these two fields.

**properties**

**userId** `string`

The `userId` of a person you identified, 1 to 128 characters. Maqetin sends to the email of their profile.

**email** `string`

An address with no profile behind it, at most 254 characters.

**from** `string` *required*

`Name <local@domain>` or `local@domain`, 3 to 320 characters on one line. Without a name, Maqetin uses the workspace name. The domain must be a verified [sending domain](https://docs.maqetin.com/messaging/sending-domains.md) of the workspace.

**subject** `string`

Replaces the subject of the template. 1 to 300 characters, on one line.

**data** `object`

Merge data for the template. It goes over the traits of the person but never over `email` or `user_id`.

In the samples, replace `templateId` with one of your templates and the domain of `from` with a verified sending domain of your workspace.

## Send it from Node

The server entry of the JavaScript SDK makes this call, and makes an idempotency key when you give none.

```ts theme={null}
import { MaqetinServer } from '@maqetin/sdk-js/server';

const mq = new MaqetinServer({ secretKey: process.env.MAQETIN_SECRET_KEY });
const { messageId } = await mq.messages.send({
  channel: 'email',
  templateId: 'tpl_receipt',
  to: { userId: 'u_42' }, // or { email: 'guest@example.com' }
  from: 'Harbour Money <receipts@mail.harbour-money.example>',
  data: { order: { id: 'o_42', total: 12.5 } },
  idempotencyKey: 'order-42:receipt',
});
```

## Send a retry safely

A retry with the same `Idempotency-Key` sends the message once and answers `202` with the same `messageId`. The first body sent with a key is the one that counts. The SDK retries after a `5xx`, a `429` or a network error with the same key, and gives up on a request that does not answer after `requestTimeoutMs`, 15 seconds by default.

## Response

A reply holds `success`, `data` and `meta`. See [Answers](https://docs.maqetin.com/api-reference/introduction.md#answers).

**data.messageId** `string` *required*

The id of the message. A contact's [messages](https://docs.maqetin.com/api-reference/contacts.md#list-the-messages-of-a-contact) carry it as `id`.

**data.status** `string` *required*

`queued`.

## Errors

A send checks the workspace, then the template, then the sender, then the recipient, and answers the first problem it finds. The `message` of a `409` names the reason in lower case, for example `Sending is not available: sender_domain_invalid.`

| Status | `error.code` | Meaning |
| - | - | - |
| `400` | `VALIDATION_FAILED` | The body, the `from` address or the `Idempotency-Key` does not parse. |
| `401` | `API_KEY_INVALID` | The request has no active secret key. |
| `403` | `FORBIDDEN` | The key has no `messages:send` scope. |
| `403` | `WORKSPACE_SUSPENDED` | The workspace of the key is suspended. |
| `409` | `SENDING_DISABLED` | Maqetin has turned sending off for now. |
| `409` | `WORKSPACE_INACTIVE` | The workspace is not active. |
| `409` | `SENDING_NOT_APPROVED` | The workspace is not approved to send yet. See [Sending approval](https://docs.maqetin.com/workspace/sending-approval.md). |
| `409` | `SENDING_PAUSED` | Maqetin has paused the sending of the workspace. |
| `404` | `NOT_FOUND` | The template is not there. |
| `409` | `SENDER_DOMAIN_INVALID` | The domain of `from` is not a verified sending domain of this workspace. |
| `404` | `NOT_FOUND` | The `userId` has no profile, or the profile has no email address. |
| `413` | `PAYLOAD_TOO_LARGE` | The body is over 100 KiB. |
| `429` | `RATE_LIMITED` | Over 300 sends a minute for the key, or over its 600 requests a minute. Wait for `Retry-After`. |

```bash cURL theme={null}
curl https://api.maqetin.com/v1/public/messages \
  -H 'Authorization: Bearer mq_sec_…' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: order-42:receipt' \
  -d '{
  "channel": "email",
  "templateId": "tpl_receipt",
  "to": { "email": "ada@example.com" },
  "from": "Receipts <receipts@mail.harbour-money.example>",
  "subject": "Your receipt",
  "data": { "order": { "id": "o_42", "total": 12.5 } }
}'
```

```json 202 theme={null}
{
  "success": true,
  "data": { "messageId": "hT3kq9Vx2LmPzQ8a", "status": "queued" },
  "meta": { "requestId": "4f8Kq2LmZ7xR1tN9pW3sY", "timestamp": "2026-12-03T09:30:00.000Z" }
}
```

```json 409 theme={null}
{
  "success": false,
  "error": {
    "code": "SENDER_DOMAIN_INVALID",
    "message": "Sending is not available: sender_domain_invalid."
  },
  "meta": { "requestId": "4f8Kq2LmZ7xR1tN9pW3sY", "timestamp": "2026-12-03T09:30:00.000Z" }
}
```


## Related topics

- [JavaScript SDK](https://docs.maqetin.com/sdk/javascript.md)
- [API reference](https://docs.maqetin.com/api-reference/introduction.md)
- [Quickstart](https://docs.maqetin.com/quickstart.md)
- [API keys](https://docs.maqetin.com/workspace/api-keys.md)
- [Contacts](https://docs.maqetin.com/data/contacts.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.