How-To

Resend/SES Message-ID overwritten: fix broken email threading

Amazon SES replaces the Message-ID you set, so a reply's In-Reply-To points to an ID your app never saved and the thread orphans. Fix it by storing the ID SES returns, reading the real header from a BCC copy, or adding a reply token, rather than matching on subject.

Sohail HussainSohail Hussain10 min read

Short answer

  • Amazon SES overrides any Message-ID you supply with its own value, so the customer's In-Reply-To points to an ID your database never saw.
  • Fix it by storing the ID that actually went out: read it from a copy of the sent message (BCC to a capture address) or from SES events, then match In-Reply-To and References against it.
  • Add a reply token in the Reply-To address as a second lookup, and never rely on sender plus subject alone.

You built your own inbox on Resend or Amazon SES. Outbound mail works, but the first reply from a customer shows up as a brand-new thread instead of attaching to the message you sent. Matching on sender plus subject was flaky, and a BCC copy to a worker was the workaround that finally held up.

This guide explains why the ID changes, how to confirm it on your own mail, and four ways to fix it, from cheapest to most thorough.

Why the Message-ID gets overwritten and replies orphan

Threading works through headers. A reply carries the parent's Message-ID in In-Reply-To and appends it to References; this is defined in RFC 5322. Your inbox looks up that value, finds the parent, and attaches the reply.

The break happens at send time. If you provide a Message-ID header, Amazon SES overrides the header with its own value. The same is documented for raw sends: Amazon SES automatically applies its own Message-ID and Date headers, replacing any you passed. So the sequence looks like this:

  1. Your app generates Message-ID: <abc123@yourapp.com> and stores it.
  2. SES discards it and writes its own value on the wire.
  3. The customer's mail client sees only the SES value and uses it in In-Reply-To.
  4. Your inbox looks up the SES value, finds nothing, and starts a new thread.

Providers that send through SES can inherit this behavior, which is why people hit it with Resend too. I could not find Resend documentation that says exactly how it treats a Message-ID you set, so test it on your own account instead of assuming either way.

Nothing is wrong on the customer's side. The one ID you needed was never recorded.

Confirm it is your problem first

  1. Send a test message from your app to a mailbox you control.
  2. Open the raw source (in Gmail, Show original) and copy the Message-ID header.
  3. Compare it with the value you stored. Paste the headers into the email header analyzer if you want them laid out; Understanding email headers covers the fields.
  4. Reply to the message, open the reply's raw source, and check In-Reply-To.

If In-Reply-To matches the received header and not your stored value, you have this bug. Also compare the part before the @ with the MessageId your send call returned. AWS describes that returned value as a unique identifier for the message that is generated when the message is accepted. The docs do not say it is identical to the header on the wire, so check that on a real message before building on it.

Fix 1: store the ID SES returns

This is the cheapest fix. Every SES send call returns a MessageId; it is the unique message identifier returned from the SendEmail action. Save it on the outbound row.

const res = await ses.send(new SendEmailCommand(params));
await db.outbound.update({
  where: { id: row.id },
  data: { sesMessageId: res.MessageId },
});

On inbound, normalize each ID in In-Reply-To and References: strip the angle brackets, take the part before @, and look it up against sesMessageId.

What it can't do: it relies on the wire header and the returned ID sharing a format you don't control. If that ever changes, lookups fail quietly. Log every inbound message that fails to match so you notice.

With Resend, the ID in the send response is Resend's own identifier. Don't assume it equals the Message-ID header recipients see; check a delivered message first.

Fix 2: BCC yourself and read the real header

If you want the ID that truly left, add a BCC to an address you control and parse that copy. It carries the header as delivered, so you never guess the format. I'd choose this if you send through more than one provider.

  1. Create a capture address such as capture@example.com, routed to a handler. Cloudflare Email Workers, an SES inbound rule or any inbound-parse webhook can do this.
  2. Add that address as BCC on every outbound send.
  3. Put your own row ID in a custom header such as X-App-Message-Ref. AWS notes that on SendRawEmail and the SMTP interface you can use custom headers in your MIME message, but test that your header survives to the BCC copy.
  4. In the handler, read the Message-ID and your custom header, match the copy to your outbound row, and save the real Message-ID.
  5. On inbound replies, look up In-Reply-To, then each entry in References, against the saved values.

The catch is timing. A very fast reply can arrive before the BCC copy is processed, so retry the lookup for a short while before creating a new thread.

Don't leak the BCC

Use a true BCC at the envelope level, not a visible Cc. If the capture address appears in the headers, customers will see it and may reply to it.

Fix 3: read the original headers from SES notifications

If you already publish SES events (see AWS's guide on specifying a configuration set when you send), the notification gives you both IDs side by side. AWS states that any message ID within the headers object is from the original message that you passed to SES, while the ID SES assigned is in the messageId field of the mail object. That lets you map your original ID to the SES one without a BCC.

Two limits. Headers only appear if you configured the notification settings to include the headers from the original email, and this still gives you SES's internal messageId, not a captured copy of the final header. Treat it as a cross-reference, then verify against a real received message as in the test above.

Fix 4: use a reply token in the Reply-To

Headers can be mangled or dropped by some clients and forwarding setups. A token in the address doesn't depend on them:

Reply-To: reply+8f3k2d@example.com

Route reply+* to your inbound handler, and the token identifies the conversation regardless of In-Reply-To. Use it as a second lookup after header matching. See Return-Path vs Reply-To for how those headers differ, and the glossary entry on the reply-to address.

Using Resend inbound for the first email

The thread suggested using Resend's inbound handling for the first message. The idea is sound: when one provider sends and receives, you may be able to read IDs from a single event stream. I could not confirm Resend's inbound payload fields from official documentation, so check Resend's current docs and verify header values on a real test before relying on it.

Match order I'd use

OrderSignalReliability
1In-Reply-To against stored real IDHigh
2Each ID in ReferencesHigh
3Reply token in the recipient addressHigh
4Normalized subject, same participants, short windowLow; flag for review

Why subject and sender matching fails

It looks like a reasonable fallback and it isn't.

  • Customers edit subjects, and clients add Re:, RE:, AW: or translated prefixes.
  • The same person writes to you about two topics under one subject, such as "Question".
  • Replies come from a different address than the one you wrote to: forwarding, aliases, a colleague.
  • Auto-replies and out-of-office messages carry the original subject and merge into the wrong thread.

Keep it only as a last resort, with a short time window and the same recipient required. A message left as a new thread is better than one attached to the wrong person's conversation.

Replying inside the thread from your app

When your app answers, set In-Reply-To to the received message's Message-ID and References to its existing chain plus that ID. Don't invent IDs. SES will overwrite the Message-ID of your reply too, so capture it with the same method you chose above. AWS also lists In-Reply-To and References among the fields that can't appear more than once in the header section, so build one of each.

Checklist before you ship

  • Sent a test, and compared the stored ID with the received Message-ID.
  • Confirmed what a reply's In-Reply-To contains.
  • Every outbound send stores a captured ID, not the one you generated.
  • Lookups check In-Reply-To, then every References entry, then the reply token.
  • Failed matches are logged, and the BCC lookup retries briefly.
  • Your own replies store their captured ID too.

If nothing works

If the IDs still don't line up after a real test, the cause may be a header rewrite you can't see from your side, such as a gateway or forwarding rule. Contact AWS Support (for SES) or Resend support, and include the raw headers of one sent message and its reply, the returned MessageId, and the send timestamp.

Subject: Message-ID on delivered mail differs from the ID returned at send

Hello,

Sending through {SES region or Resend} on {date/time UTC}. The send call returned
MessageId {id}. The delivered message shows Message-ID {header value}, and the
recipient's reply references that header value in In-Reply-To.

Please confirm:
1. Whether the delivered Message-ID is derived from the returned MessageId.
2. Whether this format is stable and supported for thread matching.
3. Whether a supported way exists to keep my own Message-ID.

Raw headers of the sent message and the reply are attached.

Where Mailneo fits

Only part of this is Mailneo's territory. If your goal is to read and answer replies to outreach sent from your own connected mailboxes, Mailneo's Unified Inbox (Professional plan and up) collects those replies in one place. It is not a library for fixing threading inside your own custom app, and it doesn't change how SES rewrites headers. If you are building a product inbox on Resend or SES, the fixes above are the answer.

Common questions

Can I stop SES from overwriting the Message-ID?

AWS documents that it replaces a Message-ID you supply, so plan around it instead of fighting it. Capture the real ID after sending.

Is the SES MessageId the same as the Message-ID header?

Often the part before the @ matches, but the AWS docs I found don't promise it. Confirm on a real delivered message and log mismatches.

Does Resend have the same problem?

Resend's send response returns its own identifier, and I could not verify how it treats a custom Message-ID. Run the header comparison test above on your account.

Is a reply token better than header matching?

It survives clients that drop headers, but it only works if replies go to your Reply-To address. Use it as a backup to headers, not a replacement.

strategyresendamazon-sescloudflare-email-workers
Share this article
Sohail Hussain

Sohail Hussain

Founder & CEO at Mailneo

Building Mailneo — AI-powered email marketing for growing businesses.

Related Articles

How-To

Email abuse report from Amazon SES: what it means, what to do

An email from complaints@email-abuse.amazonses.com is a spam complaint report, not a bounce. A recipient marked one of your messages as spam, and their mailbox provider passed it to Amazon SES. Stop mailing that person, leave them suppressed, and watch your complaint rate.

Sohail Hussain|9 min read
How-To

Is Resend down? What to do when the status page says normal

If Resend sending or login fails while its status page shows everything normal, test from outside your app, read the API response, and queue mail instead of dropping it. Long term, add a second provider and monitoring you control. A status page reports what the vendor has confirmed, not what you experience.

Sohail Hussain|9 min read
How-To

Sendy campaign stuck on Preparing: cron and PHP 8.2 fixes

A Sendy campaign stuck on Preparing, Sending or Pending usually means the cron job that runs scheduled.php is not executing. Use full paths, run it every minute under the PHP version your Sendy release supports, and read the cron log. An "ambiguous redirect" error is a shell syntax problem in your cron line.

Sohail Hussain|9 min read
How-To

414 Request-URI Too Large in n8n's Amazon SES node: fix

The error 414 Request-URI Too Large in n8n's AWS SES node means a server in the path refused a request whose URL was too long, which a long HTML body can cause when it travels in the URL. Send through the SES v2 API with an HTTP Request node, or use SES SMTP.

Sohail Hussain|9 min read

Ready to supercharge your email marketing?

Start sending smarter emails with AI-powered campaigns. No credit card required.

Get Started Free