MsgId
property MsgId: string read write;
Example
procedure SetMessageIdentity(const UniqueId: String);
var
Msg: TIdMessage;
begin
Msg := Email;
if Msg = nil then Exit;
// Use an identifier generated by a trusted application component.
Msg.MsgId := UniqueId + '@integration.example';
end;
Usage
MsgId stores the message's caller-supplied Message-ID with outer-bracket repair but no uniqueness generation or syntax validation.
Additional Technical Info
MsgId is the typed value used for the generated Message-ID header. It identifies this Internet message; it is unrelated to the IMAP mailbox UID.
Velox/Indy does not generate a Message-ID. The implementation contains disabled placeholder code, so an empty MsgId remains empty and normal GenerateHeader removes the generated header. RFC 5322 says every message should have a Message-ID, so the composing application or downstream mail infrastructure should provide a globally unique value.
Exact normalization and validation boundary
The setter calls EnsureMsgIDBrackets. For a nonempty value it independently prepends < when the first character is not < and appends > when the last character is not >. It performs no trimming, format validation, escaping, domain selection, uniqueness check or duplicate detection.
This means:
job-42@example.combecomes<job-42@example.com>;<job-42@example.com>is unchanged;- a whitespace-padded or malformed value is merely wrapped, not repaired;
- a value containing several identifiers becomes one incorrectly outer-wrapped field.
Generate a single stable id-left@id-right using a trusted uniqueness scheme. Do not use business document numbers alone where separate systems or tenants can collide, and do not place secrets or personal information in identifiers that will cross organizational boundaries and appear in logs.
Parsing, threading and reuse
ProcessHeaders reads Message-Id through the same normalizing setter. ClearHeader resets MsgId to empty. No method automatically copies it into InReplyTo or References; constructing a reply requires reading the parent identifier and explicitly setting the new message's thread fields while generating a different MsgId for the reply itself.
Normal generation writes MsgId before appending ExtraHeaders. Because ExtraHeaders allows duplicates, a later raw Message-ID entry can coexist with the typed value. Avoid adding the same structured header through both paths. NoEncode ignores MsgId and writes only raw headers.
The example is source-reviewed only; it assumes UniqueId is already unique and safe. No message was generated.
External references
- Indy upstream:
TIdMessage- Message-ID parsing, generation and disabled auto-generation block. - Indy upstream:
EnsureMsgIDBrackets- exact normalization boundary. - RFC 5322 section 3.6.4 - Message-ID syntax, uniqueness and relationship to reply fields.