# Migrating from Resend, Postmark, or SES

Source: https://molted.email/docs/migration-guide

Switch your AI agent's email sending from Resend, Postmark, or Amazon SES to Molted. Step-by-step migration with side-by-side code examples.

If you're already sending email from an AI agent using Resend, Postmark, or Amazon SES, migrating to Molted takes under an hour. Molted delivers the mail itself, through its own provider pool with failover between providers, so you don't connect your provider account. What changes is that every send now goes through a policy pipeline before delivery, and replies come back to a mailbox your agent can read.

This guide walks through the migration for each provider with side-by-side code examples.

## What changes and what stays the same

**Stays the same:**

- Your sending domain (you verify it with Molted: it gets Molted's DKIM, SPF and DMARC records, see [Domains](https://molted.email/docs/domains.md))
- Your email content (send it as-is with the `_default` template, or store it as [templates](https://molted.email/docs/templates.md))

**What changes:**

- Send calls go to Molted's Agent Runtime API (`POST /v1/agent/request-send`) instead of your provider's API
- The sender is a Molted mailbox, not a `from` field; the request names the recipient, a `templateId` and a `dedupeKey`
- You don't need your old provider account for sending through Molted

**What you gain:**

- Automatic deduplication across runs (no more re-sending because your agent forgot)
- Rate limits and plan quotas enforced at the infrastructure layer, not in your code
- Suppression list management - unsubscribes, hard bounces and complaints handled automatically
- Inbound reply handling - replies land in a classified inbox your agent can read
- Decision records - every send records whether it was allowed and why
- Provider failover - if a delivery provider goes down, sends route to another (managed by Molted)

## Before you start

1. Create a Molted account at [molted.email/signup](https://molted.email/signup) (or `molted auth signup`) and activate a plan: new workspaces can't send until one is active (see the [Quickstart](https://molted.email/docs/quickstart.md#2-choose-a-plan))
2. Add and verify your sending domain (**Settings > Domains**, or `molted domains add`). Custom domains need a paid plan; the default mailbox on the shared `agent.molted.email` domain works without one
3. Create a mailbox for your agent (in the portal: **⌘K**, `new mailbox`; or via the API or CLI below)
4. Note your `mailboxId` and API key

```bash title="Create a mailbox"
curl -X POST https://mailbox.molted.email/v1/agent/mailboxes \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "address": "agent@yourdomain.com",
    "displayName": "Outbound Agent"
  }'
```

```bash title="CLI"
molted mailboxes create --address agent@yourdomain.com --display-name "Outbound Agent"
```

The response carries the mailbox `id` to use as `mailboxId`. Each plan has a mailbox limit (see [Billing & Plans](https://molted.email/docs/billing.md)).

## Migrating from Resend

### Before (Resend)

```typescript title="Before - Resend"
import { Resend } from "resend";

const resend = new Resend(process.env.RESEND_API_KEY);

await resend.emails.send({
  from: "agent@yourdomain.com",
  to: "alice@example.com",
  subject: "Welcome to the trial",
  html: "<p>Thanks for signing up.</p>",
});
```

### After (Molted)

```typescript title="After - Molted"
const response = await fetch("https://mailbox.molted.email/v1/agent/request-send", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MOLTED_API_KEY}`,
    "Content-Type": "application/json",
    "X-Agent-Id": "my-agent", // optional: which agent is sending
  },
  body: JSON.stringify({
    mailboxId: process.env.MOLTED_MAILBOX_ID,
    recipientEmail: "alice@example.com",
    templateId: "_default",
    dedupeKey: "alice@example.com-trial-welcome",
    payload: {
      subject: "Welcome to the trial",
      html: "<p>Thanks for signing up.</p>",
      text: "Thanks for signing up.",
    },
  }),
});

const result = await response.json();

if (result.status === "blocked") {
  console.error("Send blocked:", result.reason);
  return;
}

console.log("Accepted:", result.requestId, result.status);
```

### Key differences

| Resend | Molted |
| - | - |
| `from` field sets the sender address | Sender address is the mailbox - no `from` in the request |
| No deduplication | `dedupeKey` prevents duplicate sends across runs |
| No policy engine | 30+ block reasons checked before delivery |
| No inbound replies | Replies land in the mailbox inbox |

## Migrating from Postmark

### Before (Postmark)

```python title="Before - Postmark"
import postmarker
from postmarker.core import PostmarkClient

client = PostmarkClient(server_token=os.environ["POSTMARK_API_KEY"])

client.emails.send(
    From="agent@yourdomain.com",
    To="alice@example.com",
    Subject="Welcome to the trial",
    HtmlBody="<p>Thanks for signing up.</p>",
    TextBody="Thanks for signing up.",
)
```

### After (Molted)

```python title="After - Molted"
import os
import requests

resp = requests.post(
    "https://mailbox.molted.email/v1/agent/request-send",
    json={
        "mailboxId": os.environ["MOLTED_MAILBOX_ID"],
        "recipientEmail": "alice@example.com",
        "templateId": "_default",
        "dedupeKey": "alice@example.com-trial-welcome",
        "payload": {
            "subject": "Welcome to the trial",
            "html": "<p>Thanks for signing up.</p>",
            "text": "Thanks for signing up.",
        },
    },
    headers={
        "Authorization": f"Bearer {os.environ['MOLTED_API_KEY']}",
        "X-Agent-Id": "my-agent",
    },
    timeout=10,
)
resp.raise_for_status()
result = resp.json()

if result["status"] == "blocked":
    print(f"Send blocked: {result['reason']}")
else:
    print(f"Accepted: {result['requestId']} ({result['status']})")
```

### Key differences

| Postmark | Molted |
| - | - |
| `From` / `To` in request body | Sender is the mailbox; only the recipient in the request |
| Postmark message streams for transactional vs broadcast | Autonomy levels control human-approval requirements per mailbox |
| Postmark suppressions managed per-stream | Molted suppressions apply to the whole workspace (plus a global list), auto-enforced on every send |
| Postmark webhooks for delivery events | Molted events via webhook or `molted listen` CLI stream |

## Migrating from Amazon SES

### Before (SES with AWS SDK)

```typescript title="Before - SES"
import { SESClient, SendEmailCommand } from "@aws-sdk/client-ses";

const ses = new SESClient({ region: "us-east-1" });

await ses.send(
  new SendEmailCommand({
    Source: "agent@yourdomain.com",
    Destination: { ToAddresses: ["alice@example.com"] },
    Message: {
      Subject: { Data: "Welcome to the trial" },
      Body: {
        Html: { Data: "<p>Thanks for signing up.</p>" },
        Text: { Data: "Thanks for signing up." },
      },
    },
  })
);
```

### After (Molted)

```typescript title="After - Molted"
const response = await fetch("https://mailbox.molted.email/v1/agent/request-send", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MOLTED_API_KEY}`,
    "Content-Type": "application/json",
    "X-Agent-Id": "my-agent",
  },
  body: JSON.stringify({
    mailboxId: process.env.MOLTED_MAILBOX_ID,
    recipientEmail: "alice@example.com",
    templateId: "_default",
    dedupeKey: "alice@example.com-trial-welcome",
    payload: {
      subject: "Welcome to the trial",
      html: "<p>Thanks for signing up.</p>",
      text: "Thanks for signing up.",
    },
  }),
});

const result = await response.json();
```

### Key differences

| SES | Molted |
| - | - |
| IAM credentials + region config | Single API key |
| Raw SMTP or SES API - no policy layer | 30+ block reasons checked before every send |
| No built-in deduplication | `dedupeKey` deduplication, once per workspace |
| Bounce handling via SNS/SQS pipeline | Hard bounces and complaints suppressed automatically (soft bounces after repeats) |
| Separate suppression list management | Suppressions enforced automatically |

## Handling the `dedupeKey`

The `dedupeKey` is the most important new concept in Molted. It prevents your agent from sending the same email twice if it runs multiple times, retries a failed operation, or encounters a bug. A key is used once per workspace, with no expiry: any later send with the same key, from any mailbox, gets back the first request.

**Rule:** Make the key stable and specific to the intent.

```typescript title="Good dedupeKey patterns"
// Onboarding email: one per user signup
dedupeKey: `${userId}-onboarding-welcome`

// Trial expiry reminder: one per trial period
dedupeKey: `${userId}-trial-expiry-2026-04`

// Outbound prospecting: one per prospect per campaign
dedupeKey: `${prospectId}-outbound-q2-2026`

// Support follow-up: one per ticket
dedupeKey: `ticket-${ticketId}-follow-up`
```

Avoid using timestamps or random values - these defeat the purpose and allow duplicates on retry.

## Handling policy blocks

Your code needs to handle the case where a send is blocked by policy or held for a human. This replaces the silent-drop or exception behavior you might have in existing integrations.

```typescript title="Policy block handling"
const result = await response.json();

switch (result.status) {
  case "queued":
  case "scheduled":
    // Accepted -- log the requestId for tracking
    logger.info("Email accepted", { requestId: result.requestId });
    break;

  case "pending_approval":
    // Held for a human (autonomy level, risky thread, or content check) -- not an error
    logger.info("Waiting for approval", { requestId: result.requestId, reason: result.reason });
    break;

  case "blocked":
    switch (result.reason) {
      case "duplicate":
        // This dedupeKey was used before: requestId is the ORIGINAL request.
        // Expected behavior, not an error.
        logger.info("Duplicate send prevented", { requestId: result.requestId });
        break;
      case "suppressed":
        // Unsubscribed, hard-bounced, complained, or suppressed for a legal reason
        logger.warn("Recipient suppressed", { email: recipientEmail });
        await markContactSuppressed(recipientEmail);
        break;
      case "hourly_limit_exceeded":
      case "daily_limit_exceeded":
      case "monthly_limit_exceeded":
        // Plan quota used up -- back off. A blocked send uses up its dedupeKey,
        // so a retry needs a new key (e.g. with an attempt suffix).
        logger.warn("Quota hit", { reason: result.reason });
        await scheduleRetry(payload, delayMs(60 * 60_000));
        break;
      default:
        logger.error("Send blocked", { reason: result.reason });
    }
    break;
}
```

Every blocked send is recorded under its `dedupeKey`, so sending the same key again returns `duplicate`, not a new attempt. Retry a block you have fixed (quota, plan, domain) with a new key. Run the send through `POST /v1/agent/simulate-send` first (CLI: `molted send simulate`) to see every reason it would be blocked for without using the key. See [Errors](https://molted.email/docs/errors.md) for every reason, and [What the send pipeline checks](https://molted.email/docs/why-molted.md#what-the-send-pipeline-checks) for the order.

## Delivery providers

Molted sends through its own delivery providers and fails over between them; you don't bring or configure a provider account, and there is no per-workspace provider setting. Your domain's reputation still matters: it is your domain on the From line, verified with Molted's DKIM and SPF records. A new domain warms up gradually (see [Domains](https://molted.email/docs/domains.md)).

## Checking delivery status

```typescript title="Check delivery status"
const traceResp = await fetch(
  `https://mailbox.molted.email/v1/ops/trace/${result.requestId}`,
  {
    headers: { Authorization: `Bearer ${process.env.MOLTED_API_KEY}` },
  }
);
const trace = await traceResp.json();
// { request: { status, delivery_status, ... },
//   policyDecision: { decision, reason },
//   deliveryEvents: [{ event_type, provider_name, occurred_at, ... }],
//   auditEvents: [...] }
```

`delivery_status` moves through `queued`, `accepted`, `sent` and `delivered` (or `deferred`, `bounced`, `complained`, `failed`). CLI: `molted trace <requestId>`, or `molted timeline <requestId>`.

## Reading inbound replies

Once your agent has a mailbox, replies from recipients come back to that address. Use the CLI to stream them:

```bash
molted listen --events "inbound.*"
```

The stream carries events from the mailboxes your key can reach (a mailbox-scoped key only sees its own). `--pipe <command>` hands each event to a long-running handler; `--since <eventId>` resumes after a disconnect.

Or subscribe to webhook events - see [Webhooks](https://molted.email/docs/webhooks.md) and [Reactive Agent Guide](https://molted.email/docs/reactive-agent-guide.md).

## Migration checklist

- [ ] Create a Molted account, activate a plan, and add the API key to your environment
- [ ] Verify your sending domain
- [ ] Create a mailbox for your agent, note its `mailboxId`
- [ ] Replace send calls with `POST /v1/agent/request-send`
- [ ] Add a stable `dedupeKey` to every send call
- [ ] Send `X-Agent-Id` to identify which agent is sending (optional)
- [ ] Handle `pending_approval` and `blocked` (with `reason`)
- [ ] Test with a send to your own address
- [ ] Set up inbound reply handling if your agent needs to read replies

## Related

- [Quickstart](https://molted.email/docs/quickstart.md) - full walkthrough from signup to first send
- [Sending Email](https://molted.email/docs/sending-email.md) - Agent Runtime API reference
- [Policy Simulation](https://molted.email/docs/policy-simulation.md) - test policy rules before going live
- [Domains](https://molted.email/docs/domains.md) - domain verification and DNS setup
- [Webhooks](https://molted.email/docs/webhooks.md) - delivery events and inbound notifications
- [Reactive Agent Guide](https://molted.email/docs/reactive-agent-guide.md) - build agents that respond to replies
