KosmoKrator

productivity

Mailtrap Lua API for KosmoKrator Agents

Agent-facing Lua documentation and function reference for the Mailtrap KosmoKrator integration.

Lua Namespace

Agents call this integration through app.integrations.mailtrap.*. Use lua_read_doc("integrations.mailtrap") inside KosmoKrator to discover the same reference at runtime.

Call Lua from the Headless CLI

Use kosmo integrations:lua when a shell script, CI job, cron job, or another coding CLI should run a deterministic Mailtrap workflow without starting an interactive agent session.

Inline Lua call
kosmo integrations:lua --eval 'dump(app.integrations.mailtrap.list_inboxes({}))' --json
Read Lua docs headlessly
kosmo integrations:lua --eval 'print(docs.read("mailtrap"))' --json
kosmo integrations:lua --eval 'print(docs.read("mailtrap.list_inboxes"))' --json

Workflow file

Put repeatable logic in a Lua file, then execute it with JSON output for the calling process.

workflow.lua
local mailtrap = app.integrations.mailtrap
local result = mailtrap.list_inboxes({})

dump(result)
Run the workflow
kosmo integrations:lua workflow.lua --json
kosmo integrations:lua workflow.lua --force --json
Namespace note. integrations:lua exposes app.integrations.mailtrap, app.mcp.*, docs.*, json.*, and regex.*. Use app.integrations.mailtrap.default.* or app.integrations.mailtrap.work.* when you configured named credential accounts.

MCP-only Lua

If the script only needs configured MCP servers and does not need Mailtrap, use the narrower mcp:lua command.

MCP Lua command
# Use mcp:lua for MCP-only scripts; use integrations:lua for this integration namespace.
kosmo mcp:lua --eval 'dump(mcp.servers())' --json

Agent-Facing Lua Docs

This is the rendered version of the full Lua documentation exposed to agents when they inspect the integration namespace.

Mailtrap — Lua API Reference

list_inboxes

List all inboxes in the Mailtrap account. Returns inbox IDs, names, and email addresses.

Parameters

None.

Examples

local inboxes = app.integrations.mailtrap.list_inboxes()

for _, inbox in ipairs(inboxes) do
  print(inbox.name .. " — " .. inbox.email .. " (ID: " .. inbox.id .. ")")
end

get_inbox

Get details for a specific Mailtrap inbox by ID.

Parameters

NameTypeRequiredDescription
inbox_idintegeryesThe inbox ID.

Examples

local inbox = app.integrations.mailtrap.get_inbox({
  inbox_id = 12345
})

print("Inbox: " .. inbox.name)
print("Email: " .. inbox.email)
print("Messages: " .. (inbox.messages_count or 0))

list_messages

List messages in a Mailtrap inbox with optional search and pagination.

Parameters

NameTypeRequiredDescription
inbox_idintegeryesThe inbox ID to list messages from.
pageintegernoPage number for pagination (1-based).
per_pageintegernoNumber of messages per page (default: 25).
searchstringnoSearch query to filter messages by subject, from, or to.

Examples

local result = app.integrations.mailtrap.list_messages({
  inbox_id = 12345,
  per_page = 10
})

for _, msg in ipairs(result) do
  print(msg.subject .. " from " .. msg.from_email)
end
-- Search messages
local result = app.integrations.mailtrap.list_messages({
  inbox_id = 12345,
  search = "welcome"
})

get_message

Get a single message from a Mailtrap inbox by its ID, including subject, sender, recipient, and body.

Parameters

NameTypeRequiredDescription
inbox_idintegeryesThe inbox ID.
message_idintegeryesThe message ID.

Examples

local msg = app.integrations.mailtrap.get_message({
  inbox_id = 12345,
  message_id = 67890
})

print("Subject: " .. msg.subject)
print("From: " .. msg.from_email)
print("To: " .. msg.to_email)
print("HTML body length: " .. #(msg.html_body or ""))

send_test_email

Send a test email through Mailtrap. Provide sender, recipient(s), subject, and either text or HTML body.

Parameters

NameTypeRequiredDescription
fromobjectyesSender object with email and optionally name.
toarrayyesArray of recipient objects, each with email and optionally name.
subjectstringyesEmail subject line.
textstringnoPlain text email body.
htmlstringnoHTML email body.
inbox_idintegernoInbox ID to send from (required for Testing inbox type).

Examples

local result = app.integrations.mailtrap.send_test_email({
  from = { email = "sender@example.com", name = "Sender" },
  to = { { email = "recipient@example.com", name = "Recipient" } },
  subject = "Test Email",
  text = "This is a test email sent via Mailtrap.",
  html = "<h1>Test</h1><p>This is a test email sent via Mailtrap.</p>"
})

print("Email sent successfully")

list_suppressions

List suppressions (blocked recipients) for a Mailtrap inbox.

Parameters

NameTypeRequiredDescription
inbox_idintegeryesThe inbox ID.
pageintegernoPage number for pagination (1-based).
per_pageintegernoNumber of results per page.

Examples

local result = app.integrations.mailtrap.list_suppressions({
  inbox_id = 12345
})

for _, sup in ipairs(result) do
  print("Suppressed: " .. sup.email .. " — " .. (sup.reason or "unknown"))
end

get_current_user

Get the current Mailtrap user profile and account info. Useful as a health check.

Parameters

None.

Examples

local user = app.integrations.mailtrap.get_current_user()

print("Logged in as: " .. user.email)
print("Account: " .. (user.company or "personal"))

Multi-Account Usage

If you have multiple mailtrap accounts configured, use account-specific namespaces:

-- Default account (always works)
app.integrations.mailtrap.function_name({...})

-- Explicit default (portable across setups)
app.integrations.mailtrap.default.function_name({...})

-- Named accounts
app.integrations.mailtrap.testing.function_name({...})
app.integrations.mailtrap.production.function_name({...})

All functions are identical across accounts — only the credentials differ.

Raw agent markdown
# Mailtrap — Lua API Reference

## list_inboxes

List all inboxes in the Mailtrap account. Returns inbox IDs, names, and email addresses.

### Parameters

None.

### Examples

```lua
local inboxes = app.integrations.mailtrap.list_inboxes()

for _, inbox in ipairs(inboxes) do
  print(inbox.name .. " — " .. inbox.email .. " (ID: " .. inbox.id .. ")")
end
```

---

## get_inbox

Get details for a specific Mailtrap inbox by ID.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `inbox_id` | integer | yes | The inbox ID. |

### Examples

```lua
local inbox = app.integrations.mailtrap.get_inbox({
  inbox_id = 12345
})

print("Inbox: " .. inbox.name)
print("Email: " .. inbox.email)
print("Messages: " .. (inbox.messages_count or 0))
```

---

## list_messages

List messages in a Mailtrap inbox with optional search and pagination.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `inbox_id` | integer | yes | The inbox ID to list messages from. |
| `page` | integer | no | Page number for pagination (1-based). |
| `per_page` | integer | no | Number of messages per page (default: 25). |
| `search` | string | no | Search query to filter messages by subject, from, or to. |

### Examples

```lua
local result = app.integrations.mailtrap.list_messages({
  inbox_id = 12345,
  per_page = 10
})

for _, msg in ipairs(result) do
  print(msg.subject .. " from " .. msg.from_email)
end
```

```lua
-- Search messages
local result = app.integrations.mailtrap.list_messages({
  inbox_id = 12345,
  search = "welcome"
})
```

---

## get_message

Get a single message from a Mailtrap inbox by its ID, including subject, sender, recipient, and body.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `inbox_id` | integer | yes | The inbox ID. |
| `message_id` | integer | yes | The message ID. |

### Examples

```lua
local msg = app.integrations.mailtrap.get_message({
  inbox_id = 12345,
  message_id = 67890
})

print("Subject: " .. msg.subject)
print("From: " .. msg.from_email)
print("To: " .. msg.to_email)
print("HTML body length: " .. #(msg.html_body or ""))
```

---

## send_test_email

Send a test email through Mailtrap. Provide sender, recipient(s), subject, and either text or HTML body.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `from` | object | yes | Sender object with `email` and optionally `name`. |
| `to` | array | yes | Array of recipient objects, each with `email` and optionally `name`. |
| `subject` | string | yes | Email subject line. |
| `text` | string | no | Plain text email body. |
| `html` | string | no | HTML email body. |
| `inbox_id` | integer | no | Inbox ID to send from (required for Testing inbox type). |

### Examples

```lua
local result = app.integrations.mailtrap.send_test_email({
  from = { email = "sender@example.com", name = "Sender" },
  to = { { email = "recipient@example.com", name = "Recipient" } },
  subject = "Test Email",
  text = "This is a test email sent via Mailtrap.",
  html = "<h1>Test</h1><p>This is a test email sent via Mailtrap.</p>"
})

print("Email sent successfully")
```

---

## list_suppressions

List suppressions (blocked recipients) for a Mailtrap inbox.

### Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `inbox_id` | integer | yes | The inbox ID. |
| `page` | integer | no | Page number for pagination (1-based). |
| `per_page` | integer | no | Number of results per page. |

### Examples

```lua
local result = app.integrations.mailtrap.list_suppressions({
  inbox_id = 12345
})

for _, sup in ipairs(result) do
  print("Suppressed: " .. sup.email .. " — " .. (sup.reason or "unknown"))
end
```

---

## get_current_user

Get the current Mailtrap user profile and account info. Useful as a health check.

### Parameters

None.

### Examples

```lua
local user = app.integrations.mailtrap.get_current_user()

print("Logged in as: " .. user.email)
print("Account: " .. (user.company or "personal"))
```

---

## Multi-Account Usage

If you have multiple mailtrap accounts configured, use account-specific namespaces:

```lua
-- Default account (always works)
app.integrations.mailtrap.function_name({...})

-- Explicit default (portable across setups)
app.integrations.mailtrap.default.function_name({...})

-- Named accounts
app.integrations.mailtrap.testing.function_name({...})
app.integrations.mailtrap.production.function_name({...})
```

All functions are identical across accounts — only the credentials differ.
Metadata-derived Lua example
local result = app.integrations.mailtrap.list_inboxes({})
print(result)

Functions

list_inboxes Read

List all inboxes in the Mailtrap account. Returns inbox IDs, names, and email addresses.

Lua path
app.integrations.mailtrap.list_inboxes
Full name
mailtrap.mailtrap_list_inboxes
ParameterTypeRequiredDescription
No parameters.
get_inbox Read

Get details for a specific Mailtrap inbox by ID, including its email address, settings, and message counts.

Lua path
app.integrations.mailtrap.get_inbox
Full name
mailtrap.mailtrap_get_inbox
ParameterTypeRequiredDescription
inbox_id integer yes The inbox ID.
list_messages Read

List messages in a Mailtrap inbox with optional search and pagination.

Lua path
app.integrations.mailtrap.list_messages
Full name
mailtrap.mailtrap_list_messages
ParameterTypeRequiredDescription
inbox_id integer yes The inbox ID to list messages from.
page integer no Page number for pagination (1-based).
per_page integer no Number of messages per page (default: 25).
search string no Search query to filter messages by subject, from, or to.
get_message Read

Get a single message from a Mailtrap inbox by its ID, including subject, sender, recipient, and body.

Lua path
app.integrations.mailtrap.get_message
Full name
mailtrap.mailtrap_get_message
ParameterTypeRequiredDescription
inbox_id integer yes The inbox ID.
message_id integer yes The message ID.
send_test_email Write

Send a test email through Mailtrap. Provide sender, recipient(s), subject, and either text or HTML body.

Lua path
app.integrations.mailtrap.send_test_email
Full name
mailtrap.mailtrap_send_test_email
ParameterTypeRequiredDescription
from object yes Sender object with "email" and optionally "name". E.g. {email = "me@example.com", name = "Me"}.
to array yes Array of recipient objects, each with "email" and optionally "name".
subject string yes Email subject line.
text string no Plain text email body.
html string no HTML email body.
inbox_id integer no Inbox ID to send from (required for Testing inbox type).
list_suppressions Read

List suppressions (blocked recipients) for a Mailtrap inbox.

Lua path
app.integrations.mailtrap.list_suppressions
Full name
mailtrap.mailtrap_list_suppressions
ParameterTypeRequiredDescription
inbox_id integer yes The inbox ID.
page integer no Page number for pagination (1-based).
per_page integer no Number of results per page.
get_current_user Read

Get the current Mailtrap user profile and account info. Useful as a health check.

Lua path
app.integrations.mailtrap.get_current_user
Full name
mailtrap.mailtrap_get_current_user
ParameterTypeRequiredDescription
No parameters.