Reputation: 99
I am using Delphi 10.3 with IMIBO extended MAPI.
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
Reputation: 49455
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.
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
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