Mailtrap

Send transactional and bulk email, receive inbound mail, and track delivery status in Convex apps using durable queues, signed webhooks, and reactive queries.

Installation

npm install mailtrap-convex

About Mailtrap

The Mailtrap component lets your Convex backend send, receive, and test email, for your app and for your AI agents. Live Sending is queued from mutations and delivered by a workpool with retries and backoff, so sends survive function restarts. Transactional and bulk emails go through separate streams, so critical emails stay protected. Inbound gives your app or AI agent its own inbox, with every incoming message stored in Convex. Email Sandbox catches test emails from dev and staging, so nothing reaches real users. Delivery status and inbound messages live in isolated component tables and update in real time with `useQuery`. Mailtrap is ISO 27001 certified and SOC 2 Type II audited.

Benefits

Use cases

how to send transactional email from a Convex mutation

The mailtrap-convex component exposes a sendEmail method that can be called directly inside a Convex mutation. It enqueues the send operation through a workpool action that calls the Mailtrap API with bounded retries and exponential backoff, so the mutation itself is not blocked on the HTTP call and the send survives transient failures.

how to track email delivery status in real time with Convex

mailtrap-convex registers a webhook handler at a path you mount in convex/http.ts. When Mailtrap posts delivery events such as delivered, bounce, open, or click, the component verifies the HMAC-SHA256 signature and updates the outbound row in its isolated Convex tables. You subscribe to status changes with useQuery on a query that reads from those tables.

how to receive inbound email in a Convex app

Mount the mailtrap-convex webhook handler in your Convex HTTP router and register the deployment URL in the Mailtrap Inbound dashboard. When an inbound message arrives, the component fetches the full message from the Mailtrap Inbound API and stores it in Convex indexed by inbox and thread. You can query messages by inbox or thread ID, and register an onMessageReceived callback to trigger downstream mutations or actions such as auto-replies.

how to test email sending in Convex without sending real email

Pass sandbox: true when constructing the Mailtrap instance and set MAILTRAP_TEST_INBOX_ID on your Convex deployment. All sends will route to sandbox.api.mailtrap.io and land in your Mailtrap test inbox instead of reaching real recipients, with no other code changes required.

Frequently asked questions

Does mailtrap-convex store API tokens in mutation arguments or logs?

No. mailtrap-convex reads credentials exclusively from Convex deployment environment variables: MAILTRAP_API_TOKEN, MAILTRAP_WEBHOOK_SECRET, and MAILTRAP_TEST_INBOX_ID. The Mailtrap constructor does not accept tokens as options (except an optional webhookSecret override for local testing), so tokens never appear in mutation argument logs.

What happens if the Mailtrap API is unavailable when an email is sent?

mailtrap-convex enqueues sends through a workpool action rather than calling the Mailtrap API directly from the mutation. The workpool retries the action up to 5 times by default with an initial backoff of 30 seconds. Both retryAttempts and initialBackoffMs are configurable when constructing the Mailtrap instance.

How does mailtrap-convex verify that incoming webhooks are from Mailtrap?

The handleWebhook method verifies the Mailtrap-Signature header using HMAC-SHA256 of the raw request body against the MAILTRAP_WEBHOOK_SECRET environment variable. It also deduplicates events by event_id, so replayed webhook deliveries do not produce duplicate records in Convex.

Can mailtrap-convex send to multiple recipients and use templates?

Yes. sendEmail supports to, cc, bcc, and reply_to fields, as well as html, text, attachments, custom headers, category, and custom_variables. For templated email, pass template_uuid and template_variables instead of a body. The sendBatch method uses the Mailtrap batch API and accepts up to 500 messages in a single call.

How long does mailtrap-convex retain outbound email records?

Finalized outbound rows are retained for 7 days and then removed by an hourly cron job built into the component. If you need earlier cleanup, call components.mailtrap.lib.cleanupFinalizedOutbound directly from a mutation and pass an olderThan timestamp in milliseconds.

Links

Components

Open-source building blocks for your Convex app

Browse components in this category.

Loading components