Skip to content

Add Inbound Email v2 API support#145

Open
mklocek wants to merge 7 commits into
mainfrom
inbound-v2
Open

Add Inbound Email v2 API support#145
mklocek wants to merge 7 commits into
mainfrom
inbound-v2

Conversation

@mklocek

@mklocek mklocek commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Motivation

Add SDK support for the Inbound Email v2 API, and surface the inbound-related additions that shipped on existing endpoints. Mirrors the OpenAPI spec in mailtrap-openapi.

Changes

  • Inbound Email API — new client.inbound aggregator exposing:

    • folders — list, create, get, update, delete
    • inboxes (folder-scoped) — list, create (hosted & custom-domain), get, update, delete
    • messages (inbox-scoped) — list (cursor-paginated), get, delete, reply, replyAll, forward
    • threads (inbox-scoped) — list (cursor-paginated), get, delete

    Scoped to the token's account, so client.inbound needs no accountId.

  • Email LogsEmailLogMessage now exposes rfc_message_id, in_reply_to, references, and thread_id.

  • Sending DomainsSendingDomain now exposes inbound_enabled and inbound_verified.

  • Full HTTP test coverage for every new resource + an aggregator presence test.

  • Per-resource runnable examples under examples/inbound/ and README entries.

  • Aligned the sending-domains example to import from the published mailtrap package (every example now does).

Split into reviewable commits: existing-endpoint fields, inbound types, resources + client wiring, tests, examples + README.

How to test

  • yarn lint && yarn test — 49 suites / 383 tests green.
  • Verified end-to-end against a live account: folders and inboxes CRUD, plus messages/threads including reply / reply-all / forward against a real inbound message.

Images and GIFs

N/A — SDK/API change.

Summary by CodeRabbit

  • New Features
    • Added token-scoped inbound email APIs for folders, inboxes, messages (list/get/delete, plus reply, reply-all, and forward), and threads (list/get/delete), exposed via the main client.
    • Added TypeScript types for inbound folders, inboxes, messages, and threads; extended email log and sending domain models with additional inbound-related fields.
  • Documentation
    • Updated the README with inbound email section links and added runnable inbound workflow examples.
  • Tests
    • Added unit test coverage for inbound resource operations and request/response shapes.

mklocek added 6 commits July 22, 2026 11:28
Email Log messages now expose the RFC threading headers (rfc_message_id, in_reply_to, references) and thread_id. Sending domains expose inbound_enabled and inbound_verified. Types and test fixtures updated to match the OpenAPI spec.
Folder, Inbox, Message/MessageDetails, Thread/ThreadMessage and the send (reply/forward) request+response shapes, matched to the inbound OpenAPI spec.
Folders, Inboxes, Messages (incl. reply/reply_all/forward) and Threads resources under a new InboundAPI aggregator, exposed as client.inbound. The getter needs no accountId - inbound paths are scoped to the token's account.
Full HTTP coverage (URL, method, body, response) for folders, inboxes, messages and threads, plus an InboundAPI aggregator presence test.
Per-resource runnable examples (folders, inboxes, messages incl. reply/reply_all/forward, threads) importing from the published mailtrap package, linked from the README.
Import from the published mailtrap package instead of the local source, matching the convention used by every other example.
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f1cbc45-ef11-4dd1-97e0-f57f976cfea5

📥 Commits

Reviewing files that changed from the base of the PR and between cd4daac and 302d6dd.

📒 Files selected for processing (5)
  • examples/inbound/messages.ts
  • examples/inbound/threads.ts
  • src/__tests__/lib/api/resources/inbound/Messages.test.ts
  • src/lib/api/resources/inbound/Messages.ts
  • src/types/api/inbound/messages.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • examples/inbound/messages.ts
  • src/types/api/inbound/messages.ts
  • examples/inbound/threads.ts
  • src/lib/api/resources/inbound/Messages.ts
  • src/tests/lib/api/resources/inbound/Messages.test.ts

📝 Walkthrough

Walkthrough

Adds token-scoped inbound email APIs for folders, inboxes, messages, and threads, with TypeScript contracts, Axios clients, tests, documentation links, and executable examples. Email log and sending-domain types include inbound-related metadata.

Changes

Inbound Email

Layer / File(s) Summary
Inbound API contracts
src/types/api/inbound/*, src/types/api/email-logs.ts, src/types/api/sending-domains.ts
Adds typed folder, inbox, message, thread, pagination, send-action, attachment, and inbound metadata contracts.
Inbound resource clients
src/lib/MailtrapClient.ts, src/lib/api/Inbound.ts, src/lib/api/resources/inbound/*
Exposes client.inbound and implements Axios-backed CRUD, pagination, message actions, and thread operations.
Inbound API validation
src/__tests__/lib/api/Inbound.test.ts, src/__tests__/lib/api/resources/inbound/*, src/__tests__/lib/api/resources/{EmailLogs,SendingDomains}.test.ts
Tests resource endpoints, request parameters, response handling, message actions, facade exposure, and updated fixtures.
Inbound usage examples
examples/inbound/*, README.md, examples/sending-domains/everything.ts
Adds inbound workflow examples, README links, and updates a package import path.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested labels: feature request

Suggested reviewers: leonid-shevtsov, igordobryn, piobeny

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant MailtrapClient
  participant InboundAPI
  participant InboundResource
  participant MailtrapAPI
  Application->>MailtrapClient: access client.inbound
  MailtrapClient->>InboundAPI: construct with Axios client
  InboundAPI->>InboundResource: expose folders, inboxes, messages, and threads
  Application->>InboundResource: invoke inbound operation
  InboundResource->>MailtrapAPI: send typed HTTP request
  MailtrapAPI-->>InboundResource: return inbound response
  InboundResource-->>Application: return typed result
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Inbound Email v2 API support.
Description check ✅ Passed The description matches the template well and includes motivation, changes, testing, and images/GIFs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/inbound/messages.ts`:
- Around line 28-55: The inbound examples must not mutate arbitrary existing
data: in examples/inbound/messages.ts lines 28-55, replace selection of
list.data[0].id with a user-supplied message ID and require explicit opt-in
before reply, replyAll, forward, or delete; in examples/inbound/threads.ts lines
28-36, require a user-supplied thread ID and explicit opt-in before delete,
preserving read-only behavior by default.

In `@src/lib/api/resources/inbound/Folders.ts`:
- Around line 54-57: Update the delete methods in Folders.delete
(src/lib/api/resources/inbound/Folders.ts:54-57), Inboxes.delete
(src/lib/api/resources/inbound/Inboxes.ts:66-69), Messages.delete
(src/lib/api/resources/inbound/Messages.ts:55-58), and Threads.delete
(src/lib/api/resources/inbound/Threads.ts:53-56) to return Promise<void> and
call the client delete operation with void response and data types via
delete<void, void>(...).

In `@src/types/api/inbound/messages.ts`:
- Around line 72-88: Introduce a ForwardMessageParams type with a required
non-empty to tuple ([Address, ...Address[]]), preserving the applicable
SendMessageParams fields, and update MessagesApi.forward to accept it instead of
SendMessageParams. Ensure forward calls cannot type-check without at least one
recipient while other message operations retain their existing parameter type.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c1b00f3-5b46-45ac-8d4f-bd372aeef332

📥 Commits

Reviewing files that changed from the base of the PR and between ac77421 and cd4daac.

📒 Files selected for processing (25)
  • README.md
  • examples/inbound/folders.ts
  • examples/inbound/inboxes.ts
  • examples/inbound/messages.ts
  • examples/inbound/threads.ts
  • examples/sending-domains/everything.ts
  • src/__tests__/lib/api/Inbound.test.ts
  • src/__tests__/lib/api/resources/EmailLogs.test.ts
  • src/__tests__/lib/api/resources/SendingDomains.test.ts
  • src/__tests__/lib/api/resources/inbound/Folders.test.ts
  • src/__tests__/lib/api/resources/inbound/Inboxes.test.ts
  • src/__tests__/lib/api/resources/inbound/Messages.test.ts
  • src/__tests__/lib/api/resources/inbound/Threads.test.ts
  • src/lib/MailtrapClient.ts
  • src/lib/api/Inbound.ts
  • src/lib/api/resources/inbound/Folders.ts
  • src/lib/api/resources/inbound/Inboxes.ts
  • src/lib/api/resources/inbound/Messages.ts
  • src/lib/api/resources/inbound/Threads.ts
  • src/types/api/email-logs.ts
  • src/types/api/inbound/folders.ts
  • src/types/api/inbound/inboxes.ts
  • src/types/api/inbound/messages.ts
  • src/types/api/inbound/threads.ts
  • src/types/api/sending-domains.ts

Comment thread examples/inbound/messages.ts Outdated
Comment thread src/lib/api/resources/inbound/Folders.ts
Comment thread src/types/api/inbound/messages.ts
Inbound message/thread examples are read-only by default; reply, reply-all, forward and delete are gated behind an explicit opt-in id, so running an example never sends mail or deletes data unprompted.

forward() now takes ForwardMessageParams requiring a non-empty `to`, so a recipient-less forward fails to compile.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants