How to specify the "current entry id" to GetItemFromID?

  • Thread starter ryotyankou via OfficeKB.com
  • Start date
R

ryotyankou via OfficeKB.com

Hi, Dmitry, Thank you for your help. This is not a new problem, but unsolved
one.
It's written by VC2005/ATL, an outlook plugin.
(Outlook::ApplicationEvents_11), 0x0000FAB5, OnNewMailEx
void __stdcall CXXX::OnNewMailEx(BSTR EntryId)
{
//Codes to get m_NameSpacePtr;
Outlook::_MailItemPtr NewMailItem = m_NameSpacePtr->GetItemFromID(_bstr_t
(EntryId));
}
Can this code get all current entryid? If the income e-mail is not encrypted,
the GetItemFromID can get _MailItemPtr normally. Or it will return NULL. As
you mentioned, "Are you sure you specify the right entry id? Do you get an
error? I don't think GetItemFromID can ever return null rather
than raise an exception. " But here the EntryId is pass in by Outlook, and
never be changed, What should i do with the pass-in paramater EntryId, is
there a way to make it 'current' and then pass to GetItemFromID to get the
_MailItemPtr even it is encrypted Mail item??
 
D

Dmitry Streblechenko

I am not sure what you mean by "current entry id".
What are you trying to solve? Null being retruned from GetItemFromID?
Did you try to declare NewMailItem as a generic IDispatch in case you have
something other than MailItem?

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

ryotyankou via OfficeKB.com

I'm sorry, i typed wrong word, it is not "current" but "correct". My purpose
is just to retrieve the MailItem from the pass-in paramater (BSTR entryid).
But the GetItemFormID return NULL if e-mail's encrypted.
Yes, i tried to get a generic IDispatch from GetItemFromID, it's OK, but i
have no idea what could i do with the gotten IDispatch pointer. Again, my
purpose is to get encrypted e-mail's MailItem so that i can operate the e-
mail easily. Any ideas? TIA.


Dmitry said:
I am not sure what you mean by "current entry id".
What are you trying to solve? Null being retruned from GetItemFromID?
Did you try to declare NewMailItem as a generic IDispatch in case you have
something other than MailItem?
Hi, Dmitry, Thank you for your help. This is not a new problem, but
unsolved
[quoted text clipped - 18 lines]
there a way to make it 'current' and then pass to GetItemFromID to get the
_MailItemPtr even it is encrypted Mail item??
 
D

Dmitry Streblechenko

Can you use late binding (IDispatch::GetIDsOfNames/Invoke) to retrieve the
Class property?
What do you see if you run the following script from Outlook Spy (click
"Script Editor" button on the OutlookSpy toolbar, paste the script, click
Run)

BrowseObject(Application.ActiveExplorer.Selection(1))

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
I'm sorry, i typed wrong word, it is not "current" but "correct". My
purpose
is just to retrieve the MailItem from the pass-in paramater (BSTR
entryid).
But the GetItemFormID return NULL if e-mail's encrypted.
Yes, i tried to get a generic IDispatch from GetItemFromID, it's OK, but i
have no idea what could i do with the gotten IDispatch pointer. Again, my
purpose is to get encrypted e-mail's MailItem so that i can operate the e-
mail easily. Any ideas? TIA.


Dmitry said:
I am not sure what you mean by "current entry id".
What are you trying to solve? Null being retruned from GetItemFromID?
Did you try to declare NewMailItem as a generic IDispatch in case you have
something other than MailItem?
Hi, Dmitry, Thank you for your help. This is not a new problem, but
unsolved
[quoted text clipped - 18 lines]
there a way to make it 'current' and then pass to GetItemFromID to get
the
_MailItemPtr even it is encrypted Mail item??
 
R

ryotyankou via OfficeKB.com

The result of run script is: The MailItem property page is shown. I have no
idea about the first paramater of GetIDsOfNames, i give it "_MailItem" which
i saw via OutlookSpy as its value, but return E_NOINTERFACE.
I had another try, if we can get the dispatch pointer, why not to use it to
QI the MailItem? This is the code i tried, but failed with return value
"E_NOINTERFACE", what's the wrong with my code?

Outlook::_NameSpacePtr NameSpacePtr = m_spApp->ActiveExplorer()->GetSession()
;
if(NameSpacePtr == NULL)
{
return;
}
Outlook::MAPIFolderPtr inboxFolderPtr = NameSpacePtr->GetDefaultFolder
(Outlook::eek:lFolderInbox);
if(inboxFolderPtr == NULL)
{
return;
}
IDispatch *lpDisp = NameSpacePtr->GetItemFromID(_bstr_t(EntryId), _variant_t
(inboxFolderPtr->StoreID));
if(lpDisp == NULL)
{
return;
}

HRESULT hr = S_OK;
Outlook::_MailItemPtr spMailItem;
hr = lpDisp->QueryInterface(__uuidof(Outlook::_MailItem),(void**)&spMailItem)
;
if(SUCCEEDED(hr))//always return E_NOINTERFACE
{
//do my work here
}


Dmitry said:
Can you use late binding (IDispatch::GetIDsOfNames/Invoke) to retrieve the
Class property?
What do you see if you run the following script from Outlook Spy (click
"Script Editor" button on the OutlookSpy toolbar, paste the script, click
Run)

BrowseObject(Application.ActiveExplorer.Selection(1))
I'm sorry, i typed wrong word, it is not "current" but "correct". My
purpose
[quoted text clipped - 17 lines]
 
D

Dmitry Streblechenko

That means the message is not a MailItem. Could be ReportItem, MeetingItem,
etc.
The first parameter in GetIDsOfNames is the name of the property, e.g.
"Class".

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
The result of run script is: The MailItem property page is shown. I have
no
idea about the first paramater of GetIDsOfNames, i give it "_MailItem"
which
i saw via OutlookSpy as its value, but return E_NOINTERFACE.
I had another try, if we can get the dispatch pointer, why not to use it
to
QI the MailItem? This is the code i tried, but failed with return value
"E_NOINTERFACE", what's the wrong with my code?

Outlook::_NameSpacePtr NameSpacePtr =
m_spApp->ActiveExplorer()->GetSession()
;
if(NameSpacePtr == NULL)
{
return;
}
Outlook::MAPIFolderPtr inboxFolderPtr = NameSpacePtr->GetDefaultFolder
(Outlook::eek:lFolderInbox);
if(inboxFolderPtr == NULL)
{
return;
}
IDispatch *lpDisp = NameSpacePtr->GetItemFromID(_bstr_t(EntryId),
_variant_t
(inboxFolderPtr->StoreID));
if(lpDisp == NULL)
{
return;
}

HRESULT hr = S_OK;
Outlook::_MailItemPtr spMailItem;
hr =
lpDisp->QueryInterface(__uuidof(Outlook::_MailItem),(void**)&spMailItem)
;
if(SUCCEEDED(hr))//always return E_NOINTERFACE
{
//do my work here
}


Dmitry said:
Can you use late binding (IDispatch::GetIDsOfNames/Invoke) to retrieve the
Class property?
What do you see if you run the following script from Outlook Spy (click
"Script Editor" button on the OutlookSpy toolbar, paste the script, click
Run)

BrowseObject(Application.ActiveExplorer.Selection(1))
I'm sorry, i typed wrong word, it is not "current" but "correct". My
purpose
[quoted text clipped - 17 lines]
the
_MailItemPtr even it is encrypted Mail item??
 
R

ryotyankou via OfficeKB.com

No, i don't think so, i'm sure it is a MailItem, because it is my test e-mail
(It is the case, my outlook have two accounts, A and B, i Use A send an
encrypted e-mail to B, and receive this e-mail, then the plugin will enter
OnNewMailEx(BSTR entryId) function.).

I got it, i can use GetIDsOfNames to get a class property of this income item,
but i can't get MailItem, am i right?

Dmitry said:
That means the message is not a MailItem. Could be ReportItem, MeetingItem,
etc.
The first parameter in GetIDsOfNames is the name of the property, e.g.
"Class".
The result of run script is: The MailItem property page is shown. I have
no
[quoted text clipped - 50 lines]
 
D

Dmitry Streblechenko

The whole point of retrieving the value of the Class property is to make
sure trhat you really have a MailItem object.
Try the following script in OutlookSpy: click Application button on the
OutlookSpy toolbar, go to the Script tab, paste teh script below. Now
whenever a new message arrives, OutlookSpy will open a new IDispatch browser
where you shoudl be able to see all the object properties.

sub Application_NewMailEx(EntryIDCollection)
set Msg = Application.Session.GetItemfromID(EntryIDCollection)
BrowseObject(Msg)
end sub

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
ryotyankou via OfficeKB.com said:
No, i don't think so, i'm sure it is a MailItem, because it is my test
e-mail
(It is the case, my outlook have two accounts, A and B, i Use A send an
encrypted e-mail to B, and receive this e-mail, then the plugin will enter
OnNewMailEx(BSTR entryId) function.).

I got it, i can use GetIDsOfNames to get a class property of this income
item,
but i can't get MailItem, am i right?

Dmitry said:
That means the message is not a MailItem. Could be ReportItem,
MeetingItem,
etc.
The first parameter in GetIDsOfNames is the name of the property, e.g.
"Class".
The result of run script is: The MailItem property page is shown. I have
no
[quoted text clipped - 50 lines]
the
_MailItemPtr even it is encrypted Mail item??
 
R

ryotyankou via OfficeKB.com

Thank you for your help so far, i change my way to process the incoming e-
mail, use IMessage interface instead of MailItem. These are the steps:
1.Use OpenEntry open the item to get IMessage interface.
2.Use IMessage interface query IMAPIProp interface, then make operation on
the item.
It works fine, Thank you again in advance, you are great people. ^_^

Dmitry said:
The whole point of retrieving the value of the Class property is to make
sure trhat you really have a MailItem object.
Try the following script in OutlookSpy: click Application button on the
OutlookSpy toolbar, go to the Script tab, paste teh script below. Now
whenever a new message arrives, OutlookSpy will open a new IDispatch browser
where you shoudl be able to see all the object properties.

sub Application_NewMailEx(EntryIDCollection)
set Msg = Application.Session.GetItemfromID(EntryIDCollection)
BrowseObject(Msg)
end sub
No, i don't think so, i'm sure it is a MailItem, because it is my test
e-mail
[quoted text clipped - 17 lines]
 

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