Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extracting HTML email body

1 view
Skip to first unread message

Sachin

unread,
Jun 5, 2009, 6:27:03 AM6/5/09
to
Hi
For an HTML email i want to extract Email body as HTML text instead of
plain body text . When extarct PR_BODY property it gives me plain text. How
to get the original HTML body from it ?

Thanks
Sachin

Ken Slovak - [MVP - Outlook]

unread,
Jun 5, 2009, 9:41:12 AM6/5/09
to
How about PR_HTML, a PT_BINARY (0x10130102)? Just convert the return binary
array into a string.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sachin" <Sac...@discussions.microsoft.com> wrote in message
news:A916C14D-B580-4F4C...@microsoft.com...

Sachin

unread,
Jun 8, 2009, 12:33:01 AM6/8/09
to

Getting error 0x8004010f when i tried to use PR_HTML property

pImsg->OpenProperty(PR_HTML, &IID_IStream, STGM_READ, 0,
(IUnknown**)&istream);

i have built pImsg on the top of loose msg using

hRes = OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer, MAPIAllocateMore,
MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, MAPI_UNICODE, &pIMsg);

any idea why it should fail ? the message file is HTML formatted ..

Sachin

Sachin

unread,
Jun 8, 2009, 1:19:02 AM6/8/09
to

hi
i have also tested using getProp method for property PR_HTML which returns
value 0x00040380..

"Ken Slovak - [MVP - Outlook]" wrote:

SvenC

unread,
Jun 8, 2009, 2:10:33 AM6/8/09
to
Hi Sachin,

> Getting error 0x8004010f when i tried to use PR_HTML property
>
> pImsg->OpenProperty(PR_HTML, &IID_IStream, STGM_READ, 0,
> (IUnknown**)&istream);

What do MfcMapi and/or OutlookSpy do when you try to
access PR_HTML?

--
SvenC

Dmitry Streblechenko

unread,
Jun 8, 2009, 3:15:55 AM6/8/09
to
The error is MAPI_E_NOT_FOUND, whic hmeans the property does not exist and
yu need to extract the HTML body from PR_RTF_COMPRESSED.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-


"Sachin" <Sac...@discussions.microsoft.com> wrote in message

news:46A62178-422C-41E8...@microsoft.com...

Sachin

unread,
Jun 9, 2009, 1:03:01 AM6/9/09
to

Will PR_RTF_COMPRESSED work in Unicode build ?
now in my code
hr = pIMsg->OpenProperty(
PR_RTF_COMPRESSED, &IID_IStream, STGM_READ,NULL, (LPUNKNOWN *) &istream);

returns S_OK

but how to read the istread content will istream->Read help or do i have to
take another approach as the proeprty is BINARY and not STRING type.

Sachin

Dmitry Streblechenko

unread,
Jun 9, 2009, 2:47:06 AM6/9/09
to
Yes, Unicode is handled by both RTF and HTML.
You will nee to uncompress PR_RTF_COMPRESSED property using
WrapCompressedRTFStream - search for it on the intener, there are hundreds
of examples.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Sachin" <Sac...@discussions.microsoft.com> wrote in message

news:A7F5F169-8C91-492A...@microsoft.com...

Sachin

unread,
Jun 9, 2009, 3:31:00 AM6/9/09
to

hi

i have also tried reading PR_RTF_COMPRESSED property.

hr = pIMsg->OpenProperty(
PR_RTF_COMPRESSED, &IID_IStream, STGM_READ,NULL, (LPUNKNOWN *) &istream);

//hr == S_OK

then i tried to decompress the stream
pfnWrapEx( lpCompressedRTFStream, &wcsinfo, lpUncompressedRTFStream,
&retinfo);

// here pfnWrapEx is function pointer to WrapCompressedRTFStreamEx

*(lpUncompressedRTFStream)->Read(szBody, 1024, &ulRead)

THIS RETURN szBody which looks corrupted or characters could not be
recognized .. i have tried both Code page CP_ACP and CP_UTF8

should there be any problem for unicode build of my program?


sachin

Dmitry Streblechenko

unread,
Jun 9, 2009, 10:53:00 AM6/9/09
to
You need to show more of your code.
Have you looked at the C++ samples that call that function?

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Sachin" <Sac...@discussions.microsoft.com> wrote in message

news:BB3D77BF-C745-4CF9...@microsoft.com...

SvenC

unread,
Jun 10, 2009, 5:40:49 AM6/10/09
to
Hi Sachin,

> // pfnWrapEx is a function pointer to "WrapCompressedRTFStream@12"
> in the library version which i have i cant see WrapCompressedRTFStreamEx
> function exported instead the name is "WrapCompressedRTFStream@12"
> So i assume this is the same as WrapCompressedRTFStreamEx

It cannot be the same because @12 indicates that 3 params are used but
the Ex version takes 4 params.

Download MFCMapi sources from here:
http://www.codeplex.com/MFCMAPI

That is *the* MAPI sample application and you should find how to
find the right proc and how to call it.

--
SvenC

Sachin

unread,
Jun 10, 2009, 5:25:02 AM6/10/09
to
hi Dmitry

Following is snapshot of the code
I got few sample from the net and tried it but did not work i am till
getting bad data in the buffer.

HRESULT CMapilibrary::WrapStreamForRTF( LPSTREAM lpCompressedRTFStream, BOOL
bUseWrapEx, ULONG ulFlags, ULONG ulInCodePage, ULONG ulOutCodePage, LPSTREAM
FAR * lpUncompressedRTFStream, ULONG FAR * pulStreamFlags)
{
if (!lpCompressedRTFStream || !lpUncompressedRTFStream)
return MAPI_E_INVALID_PARAMETER;

HRESULT hRes = E_FAIL;
{
if (pfnWrapEx)
{
RTF_WCSINFO wcsinfo = {0};
RTF_WCSRETINFO retinfo = {0};

retinfo.size = sizeof(RTF_WCSRETINFO);

wcsinfo.size = sizeof (RTF_WCSINFO);
wcsinfo.ulFlags = ulFlags;
wcsinfo.ulInCodePage = ulInCodePage; // Get ulCodePage from
PR_INTERNET_CPID on the IMessage
wcsinfo.ulOutCodePage = ulOutCodePage; // Desired code page for return

hRes = pfnWrapEx( lpCompressedRTFStream, &wcsinfo,
lpUncompressedRTFStream, &retinfo);
*pulStreamFlags = retinfo.ulStreamFlags;
}
else
{
fwprintf(LogFile , L"\n failed to extract RTF Body");
}
}

return hRes;
}

// pfnWrapEx is a function pointer to "WrapCompressedRTFStream@12"
in the library version which i have i cant see WrapCompressedRTFStreamEx
function exported instead the name is "WrapCompressedRTFStream@12"
So i assume this is the same as WrapCompressedRTFStreamEx

After decompresin the String i have called Read Method on it

like

body = new WCHAR[bodySize+sizeof(WCHAR)];
memset(body, 0, bodySize+sizeof(WCHAR));

hr = lpUncompressedRTFStream->Read(body, bodySize, &red);

if (hr == S_OK)
{
if (red < bodySize)
{
wprintf(L"\nRead from Email may be incomplete");
fwprintf(LogFile, L"\n Read from Email may be incomplete");
}
}
else
{
throw SE_Exception(MESSAGE_TEXT_EXTRACTION_PROBLEM) ;
}

-----------------------

but the body content is not readable and contains only boxes ..

Thanks
Sachin

Sachin

unread,
Jun 10, 2009, 5:47:01 AM6/10/09
to
Hi

i think i found the problem
1. now i am referring to MSMAPI32.dll instead of mapi32.dll which now
contains exported function for WrapCompressedRTFStreamEx

2. I was copying the data into WCHAR instead now i use ASCII buffer char*
in Read() operation so this worked and now i can see data in HTML format


-----------

I have one basic question in the same context ..
we have used PR_RTF_COMPRESSED property to read HTML mail body but i am bit
confused between difference between RTF and HTML email body

Sachin

Dmitry Streblechenko

unread,
Jun 11, 2009, 2:33:16 AM6/11/09
to
Usually HTML bod ysi encoded in the RTF stream: look at PR_RTF_COMPRESSED in
OutlookSpy (select an HTML message, click IMessage button, locate the
PR_RTF_COMPRESSED property).

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Sachin" <Sac...@discussions.microsoft.com> wrote in message

news:B6C82329-0F11-4164...@microsoft.com...

0 new messages