Unable to get Outlook Object Model _MailItem properties

A

Aditya Gupta

Hi,

We are developing a COM Add-in (in C++ language) for Outlook 2010 (beta). We
have our own custom Message Class and want to do specific tasks with this
custom message class.

Here is what we are trying to do:

1. Select the mail item with custom message class (using OOM)
2. Trap the ExplorerEvents::SelectionChange event for that mail item(using
OOM)
3. Get MAPI object (IMessage object) of that particular mail item(using OOM)
4. Modify few MAPI properties and open in a custom form viewer (using
Extended MAPI library)
5. Finally save/send the madified MAPI message (using Extended MAPI library)

The problem we are facing here is while getting the IMessage object from
_MailItem object. the API get_MAPIOBJECT returns error 0x80010105 (The server
threw an exception). Only few properties (like Message class and subject) are
fetched, rest all properties give the error 0x80010105.

Following is the piece of code:

..
..
..

CComPtr<Outlook::Selection> olSel;

hRes = m_spExplorer->get_Selection(&olSel);
if ( FAILED (hRes) )
return;

long count;
hRes = olSel->get_Count(&count);
if ( FAILED (hRes) )
return;

LPDISPATCH olSelectedItem = NULL;
CComVariant covIndex;
CComQIPtr <Outlook::_MailItem> pMailItem;

covIndex.vt = VT_I4;
covIndex.lVal = 1;
olSel->Item(covIndex,&olSelectedItem); // Get the selected item

hRes = olSelectedItem->QueryInterface(&pMailItem);
if ( FAILED(hRes) )
return;

IMessage* pMessage = NULL;
IUnknown* pUnk = NULL;

hRes = pMailItem->get_MAPIOBJECT(&pUnk); // error 0x80010105 here for all
APIs of MailItem, except message class, subject and couple more
if ( FAILED(hRes) )
return;

hRes = pUnk->QueryInterface(IID_IMessage, (void **)&pMessage);
if ( FAILED(hRes) )
return;

..
..
..


Here are my queries:
1. Is the above method to correct to get MAPI object from OOM object?
(earlier we used Exchange Client Extensions for that matter which is no
longer supported now)
2. Is there some security/trust configuration that could cause this issue?
3. I tried to get the Item properties of custom msg class using OutlookSpy.
It shows all the properties as empty/null. This is true with Outlook 2007 as
well. Is there a problem with MailItem for custom msg class?

Please comment about our approach, and also suggest some alternate way if
incorrect.

Thanks in advance,
Aditya Gupta
 
B

bigtaro

Hi,

I use the same method and it works well on outlook 2010 official release.
Maybe you could have a try!

Best Regard
-Andrew Xu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top