PR_BODY on a New Mail Item

  • Thread starter Thread starter JahMic
  • Start date Start date
J

JahMic

I keep getting a MAPI_E_NOT_FOUND whenever I try to access a New Mail
Item's PR_BODY tag via the Item's OnWrite event.

Basically, on the user side, I just open a new mail window and type in
some text in the body. Just to be sure, I make sure it's plain text
(shouldn't make a difference right?)

I have tried it through both HrGetOneProp and OpenProperty (brief
sample below). Even OutlookSpy shows it as blank. The frustrating
thing is that going through the OutlookModel.Body Property gets it for
me... Well, along with the security warning.

Any ideas?

Thanks, J

HRESULT ResultCode = HrGetOneProp(pMapiMessage, PR_BODY, &lpProps);
if (FAILED(ResultCode))
{
ResultCode = (pMapiMessage->OpenProperty(
PR_BODY,
(LPIID)&IID_IStream,
STGM_READ,
0,
(LPUNKNOWN*)&lpStream);

if (ResultCode == MAPI_E_NOT_FOUND)
{
// hmmmn, bummer.
}
 
What is the Outlook version? Do you see PR_RTF_COMPRESSED?
Also note that when OnWrite callback fires, the changes have no yet been
comiitted to the message. Use OnWriteComplete callback instead.

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

For my Dev setup, I'm using Outlook 2003, as this is our bottom end
supported ver.

I was using Outlook MailItem events, so no OnWriteComplete method (or
is there one?) In any case, I implemented the Exchange Message
extentions, checked, and sure enough on WriteComplete, the body is in
PR_RTF_COMPRESSED on the plain text option. Any way to change this?

Also, for new mail items, I was doing a lot of the processing based on
the outlook events. Is there a way to synch my OOM objects arleady
instanciated with IExchExtCallback given in WriteComplete event? I've
tried playing around GetObject() but no luck.

Once again, Thanks for the help.

J
 
Ah, sorry, I thought your were using ECE, not OOM.
What is the problem with PR_RTF_COMPRESSED? What do you want to change?
What do you mean by "synch my OOM objects"? What was the problem with
GetObject?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I guess there really isn't a problem with PR_RTF_COMPRESSED as I will
have to handle that in any case.

I was managing my new message lifetimes via the OOM objects. So, I
would like to know if I can get a pointer or something to that object
from my WriteComplete event. I saw that you wrote somewhere to use
GetObject to get the outlook object, while I can do this to get the
outlook application object via the callback interface, I get very bad
results on the MailItem. Here is what I was trying:

OLECHAR * szItem = L"MailItem";
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
DISPID dspid;
VARIANT vtResult;
lpMyDispatch->GetIDsOfNames(IID_NULL, &szItem, 1,
LOCALE_SYSTEM_DEFAULT, &dspid);
lpMyDispatch->Invoke(dspid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dispparamsNoArgs, &vtResult, NULL, NULL);
pMailItem = (_MailItemPtr)vtResult.pdispVal

Thoughts?

Thanks, J
 
I am not sure what you code is doing: you are trying to retrieve a property
named "MailItem". No Outlook object exposes a property weith that name.
Where does lpMyDispatch come from? Is it tretruend by GetObject? Try to QI
lpMyDispatch for IMailItem.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I found some sample code to achieve what I was trying:

// get The Outlook Object via IID_IOutlookExtCallback, then...
pDispatch->GetTypeInfo(0, 0, &pTypeInfo);

pTypeInfo->GetDocumentation(MEMBERID_NIL, &ClassName, 0, 0, 0);
if (0 == _tcscmp(_T("_MailItem"),(TCHAR *) (_bstr_t)ClassName);

_MailItemPtr pMailItem = pDispatch;

But I've just about giving up on doing any message changes via OOM.

Now I only have the issue of of having my message stay in my outbox as
unsent even though it has been sent. Any thoughts?

Thanks for the help, J
 
The fact the message stays in the Outbox is an indication that the
MailItem.SaveSentMessageFolder property (corresponds to PR_SENTMAIL_ENTRYID
in MAPI) has not been set, What is your code?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
When I changed SaveChanges from FORCE_SAVE to KEEP_OPEN_READWRITE, it
started behaving a lot better. Occasionally, it will stay in the
Drafts (but at least not as a copy) until the next send/receive
processing cycle. That is something I can live for now.

Thanks for the help,

J
 
Back
Top