New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
SMTP and APIUpdated 26 Oct 2026

Message-ID Header Explained: Format, Uniqueness, Threading and Debugging

What the Message-ID header is, how to generate a valid one, why a missing or malformed ID hurts delivery, how In-Reply-To and References build threads, and how to use the ID to trace a message.

TK
Written by Tomasz Kowalski
Infrastructure and Reliability Engineer
Reviewed by Mateus Oliveira
  • Published30 Mar 2026
  • Read time6 min
  • Length1,319 words
Share this guide

Every email message should carry a Message-ID header, a unique label that identifies that exact message. Mail clients use it to build conversation threads and to remove duplicates, mail servers write it in logs so that administrators can follow a message through a chain of systems, and spam filters look at it as one of many small signals of whether the sender is a real mail system. Most of the time the ID is generated for you and nobody notices it. It becomes important when you send mail from your own code, when you switch providers, when replies fail to thread, when a message is delivered twice or when you need to find one message among millions in a log. This guide explains the format defined by the standard, how to generate good IDs, what happens when you leave it out, how it relates to In-Reply-To and References for threading and how to use it as a tracing key in practice.

HeaderMessage-ID: a globally unique identifier in angle brackets
Form<unique-part@domain>, defined by RFC 5322
UsesThreading, deduplication, log correlation, bounce matching
RuleGenerate once per message; never reuse; keep it when you forward or retry

The format

A Message-ID has the form <left@right>. The part on the left is any string of permitted characters that makes the ID unique; the part on the right is normally a domain name or the hostname of the system that generated it. The angle brackets are part of the value. A typical example looks like this:

Message-ID: <[email protected]>
Date: Mon, 26 Oct 2026 10:15:00 +0000
From: Example <[email protected]>
To: [email protected]
Subject: Your receipt

The standard asks for global uniqueness, which you achieve by combining something unique on the left (a timestamp with high resolution plus a random string, or a UUID) with a right-hand side that you control. Because the domain belongs to you, no other system will generate the same ID. The left side must not contain spaces or characters that need quoting, and the total length should stay modest, because some software limits lines to 998 characters and mail clients may truncate long values.

Which domain to use on the right

ChoiceProsCons
Your sending domain (example.com)Matches the From domain; looks consistent to filtersNeeds care not to collide with IDs created by other systems that use the same domain
A mail subdomain (mail.example.com)Separates IDs by system or stream; easy to traceAnother name to manage
The server hostnameTraditional; shows which host created the messageMay expose internal names; may not match anything in DNS
localhost or an IP literalNoneLooks like a script; commonly penalised by spam filters
The provider's domainThe provider generates it for youThe ID says nothing about your system

Spam filters have long checked for IDs that look machine-made and careless, such as those ending in @localhost, @localhost.localdomain or a name that is clearly not a real domain. A domain that resolves in DNS and relates to the sender is a modest positive signal. No filter will accept or reject a message on this header alone, but it is one of several things that distinguish well-formed mail from sloppy mail. Read how content filters judge a message.

What happens if it is missing

The standard says that a Message-ID should be present. If your application does not add one, many mail servers will add it for you on submission, and some relays will too. If it is added late, you lose the ability to know the ID at the moment you sent the message, which makes tracing harder. If nothing adds it, the message may be treated with more suspicion, some filters add a small penalty for a missing header, and threading by clients that rely on it may fail. For this reason you should either let your sending library generate it or set it yourself. Most libraries do so by default: PHPMailer, Nodemailer, Python's email.utils.make_msgid() and Java Mail all have helpers.

# Python: generate a Message-ID on your own domain
from email.utils import make_msgid
msg['Message-ID'] = make_msgid(domain='mail.example.com')

Threading: In-Reply-To and References

When a user replies to a message, the client writes two headers. In-Reply-To holds the Message-ID of the message being answered. References holds the chain: the IDs of earlier messages in the conversation, with the most recent last. Mail clients and webmail use these to place the reply in the right thread. If you send automated follow-ups and want them to appear in the same conversation, copy the original Message-ID into In-Reply-To and append it to References. The subject line should also match, with the usual "Re:" prefix, because some clients thread by subject as a fallback.

Message-ID: <[email protected]>
In-Reply-To: <[email protected]>
References: <[email protected]>
Subject: Re: Your receipt

For support systems and inbound parsing it works in the opposite direction: when a customer replies, your system reads In-Reply-To or References to attach the reply to the right ticket. See inbound email processing. Be careful that a provider may rewrite the Message-ID when it relays; if you rely on the ID to thread replies, store the ID that appears in the delivered message, not only the one you generated.

Using the ID to trace a message

The Message-ID is the key that ties together records in different systems: your application log, the provider's message log, the recipient's headers and a bounce message. When a customer says that an email never arrived, ask for the time and the recipient, find the message in your logs and note its ID. A provider with a message log can then show the delivery events for that ID. In a bounce, the original headers are often included, so the ID lets you match a bounce to the message that caused it. In a complaint feedback report the original message or its headers are included for the same reason. See tracing email with message logs and reading headers.

Common problems

ProblemCauseFix
Replies do not threadIn-Reply-To or References missing, or the provider replaced the IDStore the delivered ID and copy it into the follow-up
Message appears twice for one recipientRetry sent a second message with a new ID after an ambiguous failureUse a stable ID per logical message and an idempotency check
Two different messages share an IDWeak generator, for example a timestamp in seconds onlyAdd random bytes or use a UUID
ID ends with localhostLibrary default on a server without a hostnameSet the domain explicitly
Cannot find a message in provider logsSearching by an ID the provider changedSearch by recipient and time, or ask the API for the provider ID
Header rejected as malformedMissing angle brackets, spaces, non-ASCII charactersFollow the format strictly

Good practice for developers

  1. Generate the ID in your application, on a domain you control, with at least 64 bits of randomness or a UUID.
  2. Save it with the record of the send, along with the recipient and the time.
  3. Keep the same ID when you retry the same logical message, so that duplicates are easy to spot.
  4. Do not put personal data, such as an email address or user name, in the left part. IDs appear in headers that third parties can read.
  5. Preserve existing IDs when you forward or redirect, and add new ones only to new messages.
  6. Return the ID, or the provider's equivalent, to your own system so that support staff can look it up.

The Message-ID is a small header with a large effect on how easily you can run an email system. A correct, unique ID costs nothing to produce and pays back every time you need to find, thread or de-duplicate a message.

Trace every message you send Message logs and event webhooks let you follow a message from API call to delivery.

See the email API

References and further reading

Frequently asked questions

What is the Message-ID header?

A unique identifier for one email message, written as <unique-part@domain>. Clients use it for threading and servers use it in logs.

Does a missing Message-ID hurt deliverability?

It can. Many systems add one, but a missing or sloppy ID, such as one ending in localhost, is a minor negative signal.

How do I make replies thread correctly?

Copy the original Message-ID into In-Reply-To, append it to References and keep a matching Re: subject.

Which domain should I use in the Message-ID?

A domain or subdomain you control, ideally related to your sending domain.

Can I use the Message-ID to find a message in logs?

Yes. It is the main correlation key between your application, your provider's log, headers and bounces.

Topics#message-id#email headers#threading#rfc 5322#debugging
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales