Topic Path: Symbol Reference > Classes > TIdMessage Class > TIdMessage Methods > LoadFromFile Method
TIdMessage.LoadFromFile Method

Loads message headers and message parts from a file.

procedure LoadFromFile(
    const AFileName: string; 
    const AHeadersOnly: Boolean = False
File containing values to load into the message.
Indicates if only headers for the message should be loaded from the file. Default value is False. 

LoadFromFile is a procedure that loads the headers and optional contents for a message from the file name specified in AFilename. If AFilename is not a valid file name on the the local file system, an EIdMessageCannotLoad exception will be raised and the method will be aborted. 

Existing content in the TIdMessage instance is cleared prior to loading the values found in the specified file name. 

LoadFromFile creates an instance of TFileStream to be used to reading the values for the message instance. The file stream is created using the file mode constants that allow shared read with denied write priviliges (fmOpenRead fmShareDenyWrite). LoadFromFile calls LoadFromStream using the file stream to perform the physical input operation. The TFileStream instance is freed prior to exiting from the method. 

When AHeadersOnly is True, only header values up to and including the blank line delimiter in RFC message headers will be read from the input file. When AHeadersOnly is False, both message Headers and MessageParts will be read and stored in the message instance. 

Use SaveToFile to create a file suitable for use with LoadFromFile. Use LoadFromSteam to read message contents from a TStream descendant. Use SaveToStream to populate a stream with values suitable for use with LoadFromSteam. 

Both LoadFromFile and LoadFromStream are designed to handle messages written using the SaveToStream or SavedToFile methods in the Indy TIdMessage component. These methods create an encoded version of the message contents that matches the protocol tranmissions used when the message is transmitted using TIdSMTP including the message terminator characters (CRLF.CRLF). If you are trying to import .EML message files from MS Outlook Express, or another email client, make sure that the text file contains the message terminator sequence. An exception will be raised if LoadFromFile or LoadFromStream are used to load files that do not include the message terminator sequence. 

Please not that TIdMessage has no pre-defined mechanism that determines paths or file names used for local storage of message instances. That is an implementation detail specific to the mail or news client constructed using the Indy components.

Raised with the message RSIdMessageCannotLoad when the specified file name does not exist.
Raised with the message RSMsgClientUnkownMessagePartType when an unknown message part type is encountered when processing the body of a message part. 

[Delphi] Loading a message instance from a disk file. 


  // var Msg: TIdMessage;
  // Msg := TIdMessage.Create(Nil);

  // load headers only
  Msg.LoadFromFile(sStorePath + sFilename, True);

  // load complete message including message parts
  Msg.LoadFromFile(sStorePath + sFilename, False);

  // Msg.Free;
Copyright 1993-2006, Chad Z. Hower (aka Kudzu) and the Indy Pit Crew. All rights reserved.
Post feedback to the Indy Docs Newsgroup.