//uses IdText...
procedure TForm1.ExtractPlainTextFromEMLFileContainingHTMLMail;
// Drop a TIdMessage component on the form and name it "IdMessage"
var
IndyStringList: TStringList;
IndyStream: TMemoryStream;
I: Integer;
const
CRLF = #13#10;
begin
IndyStringList := TStringList.Create;
IndyStream := TMemoryStream.Create;
try
IndyStringList.LoadFromFile('
C:\Ihre Bestellung.eml');
IndyStringList.Add(CRLF + '
.' + CRLF);
IndyStringList.SaveToStream(IndyStream);
IndyStream.Position := 0;
IdMessage.Clear;
IdMessage.LoadFromStream(IndyStream);
Memo1.Clear;
Memo1.Lines.Assign(IdMessage.Headers);
Memo2.Clear;
Memo2.Lines.Add(IdMessage.From.Text);
Memo2.Lines.Add(IdMessage.Recipients.EMailAddresses);
Memo2.Lines.Add(IdMessage.Subject);
Memo2.Lines.Add(DateTimeToStr(IdMessage.Date));
Memo2.Lines.Add('
');
for I := 0
to IdMessage.MessageParts.Count - 1
do
if IdMessage.MessageParts.Items[I]
is IdText.TidText
then
begin
Memo2.Lines.Add(IdText.TidText(IdMessage.MessageParts.Items[I]).Body.Text);
// This is called TWICE. The first time it gets this text:
// 'This is a multi-part message in MIME format.'
// The second time it gets the HTML code of the message body
// So how can I get the plain-text of the message body?
end;
finally
IndyStringList.Free;
IndyStream.Free;
end;
end;