Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Netzwerke (https://www.delphipraxis.net/14-netzwerke/)
-   -   Delphi TIDIMAP4 - Mail Body als reinen text bekommen ? (https://www.delphipraxis.net/146871-tidimap4-mail-body-als-reinen-text-bekommen.html)

moelski 28. Jan 2010 13:33


TIDIMAP4 - Mail Body als reinen text bekommen ?
 
Moin !

Kann mir jemand mal kurz nen Tip geben wie ich an den Body, also den normalen Text einer Mail komme?

Habe es so probiert:
Delphi-Quellcode:
function TGetMails.GetMailDetails(Part : TMailParts; ID : Integer) : string;
var TheMsg : TIdMessage;
    TheUID : string;
    nCount : integer;
    TheBody : string;
begin
  TheMsg := TIdMessage.Create(nil);
  nCount := TheImap.MailBox.TotalMsgs;
  if nCount = 0 then begin
    ShowMessage('There are no messages in ' + TheImap.MailBox.Name);
    Exit;
  end else begin
    TheImap.GetUID (ID + 1, TheUID);
    TheImap.Retrieve(ID + 1, TheMsg);
  end;

  case Part of
    ....
    Part_Body          : GetMailDetails := TheMsg.body.text;
    ....
  end;
  TheMsg.Destroy;
end;
Aber das will nicht so recht. Da bekomme ich als Ergebnis wenn ich eine RTF oder HTML Mail im Posteingang habe :
Zitat:

This is a multi-part message in MIME format.
Kann mir jemand sagen wie ich an den "reinen Text" der Mail komme?

Assertor 28. Jan 2010 14:12

Re: TIDIMAP4 - Mail Body als reinen text bekommen ?
 
Hi moelski,

Das mit dem Body ist korrekt. Die Texte sind über die MessageParts verstreut:

Du mußt durch alle Text-Elemente in MessageParts iterieren:

Delphi-Quellcode:
var
  i: Integer;
begin
  ...
  for i := IdMessage.MessageParts.Count - 1 downto 0 do
  begin
    if (IdMessage.MessageParts[i] is TIdText) and
       (IdMessage.MessageParts[i].ContentType = 'text/html') then
    begin  
      Memo1.Lines.AddString((IdMessage.MessageParts[i] as TIdText).Body);
    end;
  end;
end;
Gruß,

Assertor


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:05 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz