Board index » delphi » How to load an E-Mail (.EML) from a file to an TIdMessage ?

How to load an E-Mail (.EML) from a file to an TIdMessage ?

How to load an E-Mail (plain text as Outlook Express .EML) from a file to an
TIdMessage ?

I have created this proc, but don't works correctly becouse the body part
still reamain undecoded: don't exists a GetBody procedure performing the
same work of GetHeader !

Procedure LoadMessageFromDisk(MailMessage:TIdMessage;FileName:String);
 Var

  MailFile:Text;
  MailLine:String;
  HeaderDone:Boolean;

begin
  AssignFile(MailFile,FileName);
  Reset(MailFile);
  try
   HeaderDone:=False;
   While Not Eof(MailFile) do
    begin
     Readln(MailFile,MailLine);
     if (not HeaderDone) and (Length(MailLine)=0) then
      begin
       HeaderDone:=True;
       MailMessage.GetHeader;
      end
     else
      begin
       if HeaderDone
        then  MailMessage.Body.Add(MailLine)
        else  MailMessage.Headers.Add(MailLine)
    end;
   // NOW I NEED TO DECODE THE BODY !!  HOW TO ??
  finally
   CloseFile(MailFile);
  end;
end;

Thanks for you help !

Francesco (Italy)

 

Re:How to load an E-Mail (.EML) from a file to an TIdMessage ?


Quote
"Francesco Pucino" <fpuc...@mclink.it> wrote in message

news:3c066222$1_2@dnews...

Quote
> How to load an E-Mail (plain text as Outlook Express .EML) from a file to
an
> TIdMessage ?

> I have created this proc, but don't works correctly becouse the body part
> still reamain undecoded: don't exists a GetBody procedure performing the
> same work of GetHeader !

for 9.02 use:

IdMessage := TIdMessage.Create(nil);
  try
    RawData := TMemoryStream.Create;
    try
      Memo1.Lines.SaveToStream(RawData);
      // Append closing octet
      RawData.Write('.'#10#13, 3);
      // Reset data pointer
      RawData.Seek(0, soFromBeginning);
      // Load data into message
      IdMessage.loadFromStream(RawData);
    finally
      RawData.Free;
    end;

    // And convert it back to text
    RawData := TMemoryStream.Create;
    try
      // Save message to data stream
      IdMessage.SaveToStream(RawData);
      // Reset data pointer
      RawData.Seek(0, soFromBeginning);
      // Load data into memo
      Memo2.Lines.loadFromStream(RawData);
    finally
      RawData.Free;
    end;

  finally
    IdMessage.Free;
  end;

Rgds,

Ewart

Re:How to load an E-Mail (.EML) from a file to an TIdMessage ?


Quote
"Ewart Nijburg" <enijburg@_snip_bigfoot.com> wrote in message

news:3c06b610_2@dnews...

Quote
> "Francesco Pucino" <fpuc...@mclink.it> wrote in message
> news:3c066222$1_2@dnews...
> > How to load an E-Mail (plain text as Outlook Express .EML) from a file
to
> > an TIdMessage ?

For 9.0.2B, you can use TIdMessage.SaveToFile.

Re:How to load an E-Mail (.EML) from a file to an TIdMessage ?


Thanks.

I'm using the version 8.0.22. The version 9.02 is full compatible and stable
?

"Ewart Nijburg" <enijburg@_snip_bigfoot.com> ha scritto nel messaggio
news:3c06b610_2@dnews...

Quote

> "Francesco Pucino" <fpuc...@mclink.it> wrote in message
> news:3c066222$1_2@dnews...
> > How to load an E-Mail (plain text as Outlook Express .EML) from a file
to
> an
> > TIdMessage ?

> > I have created this proc, but don't works correctly becouse the body
part
> > still reamain undecoded: don't exists a GetBody procedure performing the
> > same work of GetHeader !

> for 9.02 use:

> IdMessage := TIdMessage.Create(nil);
>   try
>     RawData := TMemoryStream.Create;
>     try
>       Memo1.Lines.SaveToStream(RawData);
>       // Append closing octet
>       RawData.Write('.'#10#13, 3);
>       // Reset data pointer
>       RawData.Seek(0, soFromBeginning);
>       // Load data into message
>       IdMessage.loadFromStream(RawData);
>     finally
>       RawData.Free;
>     end;

>     // And convert it back to text
>     RawData := TMemoryStream.Create;
>     try
>       // Save message to data stream
>       IdMessage.SaveToStream(RawData);
>       // Reset data pointer
>       RawData.Seek(0, soFromBeginning);
>       // Load data into memo
>       Memo2.Lines.loadFromStream(RawData);
>     finally
>       RawData.Free;
>     end;

>   finally
>     IdMessage.Free;
>   end;

> Rgds,

> Ewart

Other Threads