Body
property Body: TStrings read write;
Example
procedure SetPlainBody(const Text: string);
var
Msg: TIdMessage;
begin
Msg := Email;
if Msg = nil then Exit;
Msg.Body.Clear;
Msg.Body.Add(Text);
end;
Usage
Body exposes the message-owned line collection used as plain content, MIME preamble or raw no-decode payload depending on the processing mode.
Additional Technical Info
Body returns the live TStringList owned by the TIdMessage. The message creates it once and frees it on destruction. Do not free the returned object or cache it beyond the message/action lifetime.
Assigning another TStrings does not replace the owned list; the setter calls Body.Assign(value). Existing lines are replaced and normal TStrings assignment exceptions propagate. Passing a nil object is not guarded. Direct operations such as Clear, Add, Text and indexed access mutate the same collection immediately.
Meaning depends on message layout
- For a simple
mePlainTextmessage, Body is the main content. - For multipart MIME, Body is normally the preamble before the first boundary; the actual text alternatives belong in
MessagePartsasTIdTextitems. - With
ConvertPreambletrue, a nonempty Body can instead be copied into an automatically appended text part during output when the collection has other parts but no text part. - With
NoDecodetrue during receive, the entire remaining wire body is captured into Body without MIME or transfer decoding; no attachment/text parts are constructed. - With
NoEncodetrue during output, Body is the only body collection written and MessageParts are ignored.
ClearBody destroys every message part first and then clears this list. Loading is also destructive because LoadFromStream calls Clear before parsing.
Line storage is textual, not a byte-preserving MIME buffer. Text joins/splits lines using Delphi string-list conventions; save code applies RFC line writing and dot transparency. Charset and transfer transformations depend on the surrounding mode, CharSet and transfer-encoding fields. Do not assume that load followed by save is byte-for-byte lossless.
The example is source-reviewed and performs no mail operation. For large bodies, repeated Text reads allocate combined strings; prefer bounded line operations where practical.
External references
- Indy upstream:
IdMessage.pas- owned list, assignment and clear behavior. - Indy upstream:
IdMessageClient.pas- receive/send interpretation of Body. - Embarcadero DocWiki:
System.Classes.TStrings- Delphi line-collection API andAssignbehavior. - Free Pascal:
TStrings- compatible core collection reference; Velox uses Delphi. - RFC 2046, multipart preamble - MIME preamble and boundary model.