mazluta
mazluta

Reputation: 99

how to save extended-mapi imessage as html

I am using Delphi 10.3 with IMIBO extended MAPI.

  1. Is it possible to save IMessage as HTML?
  2. If no, is it possible to convert IMessage to MailItem.MAPIObject and use MailItem to save as HTML

This works fine, but takes too long:

procedure TForm7.Button1Click(Sender: TObject);
const
  olMailItem = 0;
var
  Outlook    : OleVariant;
  FNameSpace : OleVariant;
  vMailItem  : variant;
begin


  Outlook := CreateOleObject('Outlook.Application');
  FNameSpace := Outlook.GetNamespace('MAPI');
  FNameSpace.Logon;
  vMailItem := FNameSpace.OpenSharedItem('c:\3\aa.msg');

  ShowMessage(vMailItem.Subject);

  //olHTML, olMSG, olRTF, olTemplate, olDoc, olTXT, olVCal, olVCard, olICal, or olMSGUnicode.
  vMailItem.SaveAs('c:\3\aa.html', olHTML);

  VarClear(vMailItem);
  VarClear(FNameSpace);
  VarClear(Outlook);
end;

Upvotes: 1

Views: 207

Answers (2)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

  1. To retrieve the complete message body with images you need to retrieve the PR_BODY_HTML property value which contains the HTML markup. See Retrieving MAPI Properties for more information on that.

    To get the message body with images you need to search for <img> tags in the markup and check their location, i.e. whether any of them are referring to the embedded images. If so, you need to save attached images to the same folder with HTML markup to get the message body displayed correctly, of course, with some modififcations by removing the CID prefix from the <img> tag.

  2. There is no direct cast. Instead, you can use the PR_ENTRYID property value to retrieve a corresponding item from the OOM by using the NameSpace.GetItemFromID method which returns a Microsoft Outlook item identified by the specified entry ID (if valid). This method is used for ease of transition between MAPI and OLE/Messaging applications and Outlook.

Upvotes: 1

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66316

Of course, but you'd have to build the HTML yourself from all the gory MAPI properties. There is nothing in MAPI that exports a message in anything but MSG format.

Upvotes: 1

Related Questions