Searching outlook folders

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am using the following code to search for an email message with id myID;

Dim SentFld As Outlook.MAPIFolder
Dim Email As Outlook.MailItem
Dim I As Integer
OutlookApp = New Outlook.Application

SentFld =
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText, True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 
Hi John,
I remember me that I had the same problem a very long time ago.

But then I thougth the problem was the time to load the folder over the
network and not the search, I had no solution, but can it be this is the
same problem?

I know it does not help, but I ask this to get it easier for others to help
you, and then maybe I know the solution too then.

Cor
 
You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom
 
Hi

Can I get an example of how to access the entryid for a new mail item? I
presume it can be search using; Email = SentFld.Items.Find("[EntryID]=""" &
myEntryID & """")?

Thanks

Regards


Tom Rizzo said:
You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.



John said:
Hi

I am using the following code to search for an email message with id myID;

Dim SentFld As Outlook.MAPIFolder
Dim Email As Outlook.MailItem
Dim I As Integer
OutlookApp = New Outlook.Application

SentFld =
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText, True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 
Keep in mind that you can kill your Exchange server if you are using
Restrict rather than Find/FindNext - Exchange caches restrictions for about
1 week by default and updates the restriction results everytime any message
in the folder changes.

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


Tom Rizzo said:
You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.



John said:
Hi

I am using the following code to search for an email message with id myID;

Dim SentFld As Outlook.MAPIFolder
Dim Email As Outlook.MailItem
Dim I As Integer
OutlookApp = New Outlook.Application

SentFld =
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText, True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 
If you already know the entry id, you can simply use
Namespace.GetItemFromID() to open it.

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


John said:
Hi

Can I get an example of how to access the entryid for a new mail item? I
presume it can be search using; Email = SentFld.Items.Find("[EntryID]=""" &
myEntryID & """")?

Thanks

Regards


Tom Rizzo said:
You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no rights.
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText, True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 
Hi Dmitry

Anywhere I can get more information on this?

Thanks

Regards


Dmitry Streblechenko said:
If you already know the entry id, you can simply use
Namespace.GetItemFromID() to open it.

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


John said:
Hi

Can I get an example of how to access the entryid for a new mail item? I
presume it can be search using; Email =
SentFld.Items.Find("[EntryID]="""
&
myEntryID & """")?

Thanks

Regards
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText,
True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to search
for emails with specific user defined ids?

Thanks

Regards
 
Outlook VBA help file:

GetItemFromID Method

See Also Applies To Example Specifics
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.

expression.GetItemFromID(EntryIDItem, EntryIDStore)

expression Required. An expression that returns a NameSpace object.

EntryIDItem Required String. The EntryID of the item.

EntryIDStore Optional Variant. The StoreID for the folder.

Remarks
EntryIDStore usually must be provided when retrieving an item based on its
MAPI IDs.


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


John said:
Hi Dmitry

Anywhere I can get more information on this?

Thanks

Regards


Dmitry Streblechenko said:
If you already know the entry id, you can simply use
Namespace.GetItemFromID() to open it.

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


John said:
Hi

Can I get an example of how to access the entryid for a new mail item? I
presume it can be search using; Email =
SentFld.Items.Find("[EntryID]="""
&
myEntryID & """")?

Thanks

Regards


You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be much
faster to find using the built-in methods for finding via ID.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no
rights.



Hi

I am using the following code to search for an email message with id
myID;

Dim SentFld As Outlook.MAPIFolder
Dim Email As Outlook.MailItem
Dim I As Integer
OutlookApp = New Outlook.Application

SentFld =
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText,
True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to
search
for emails with specific user defined ids?

Thanks

Regards
 
Thanks. Now what remains is how to know the entryid of a mailitem when it is
saved/sent, so it can be referenced later.

Thanks

Regards


Dmitry Streblechenko said:
Outlook VBA help file:

GetItemFromID Method

See Also Applies To Example Specifics
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.

expression.GetItemFromID(EntryIDItem, EntryIDStore)

expression Required. An expression that returns a NameSpace object.

EntryIDItem Required String. The EntryID of the item.

EntryIDStore Optional Variant. The StoreID for the folder.

Remarks
EntryIDStore usually must be provided when retrieving an item based on its
MAPI IDs.


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


John said:
Hi Dmitry

Anywhere I can get more information on this?

Thanks

Regards
item?
I
presume it can be search using; Email = SentFld.Items.Find("[EntryID]="""
&
myEntryID & """")?

Thanks

Regards


You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID on the
mailitem). You may just want to store and use that ID which will be
much
faster to find using the built-in methods for finding via ID.

Tom

--
Looking for a good book on programming Exchange, Outlook, ADSI and
SharePoint? Check out http://www.microsoft.com/MSPress/books/5517.asp

This posting is provided "AS IS" with no warranties, and confers no
rights.



Hi

I am using the following code to search for an email message
with
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID", Outlook.OlUserPropertyType.olText,
True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster way to
search
for emails with specific user defined ids?

Thanks

Regards
 
When an item is sent, its entry id changes when it is moved to the Sent
Items folder. Use MAPIFolder.Items.ItemAdd event (where MAPIFolder points to
Sent Items folder) to save the entry id of the item.

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


John said:
Thanks. Now what remains is how to know the entryid of a mailitem when it is
saved/sent, so it can be referenced later.

Thanks

Regards


Dmitry Streblechenko said:
Outlook VBA help file:

GetItemFromID Method

See Also Applies To Example Specifics
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.

expression.GetItemFromID(EntryIDItem, EntryIDStore)

expression Required. An expression that returns a NameSpace object.

EntryIDItem Required String. The EntryID of the item.

EntryIDStore Optional Variant. The StoreID for the folder.

Remarks
EntryIDStore usually must be provided when retrieving an item based on its
MAPI IDs.


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


John said:
Hi Dmitry

Anywhere I can get more information on this?

Thanks

Regards


If you already know the entry id, you can simply use
Namespace.GetItemFromID() to open it.

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


Hi

Can I get an example of how to access the entryid for a new mail
item?
I
presume it can be search using; Email =
SentFld.Items.Find("[EntryID]="""
&
myEntryID & """")?

Thanks

Regards


You could try the restrict method rather than the find method. Also,
Outlook has unique ID's on every item called the EntryID (or ID
on
the
mailitem). You may just want to store and use that ID which
will
OutlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMai
l)
iCount = SentFld.Items.Count
Email = CType(SentFld.Items.Item(1), Outlook.MailItem)
Email.UserProperties.Add("EmailID",
Outlook.OlUserPropertyType.olText,
True)
Email = SentFld.Items.Find("[EmailID]=""" & myID & """")

The problem is that the find is very slow. Is there a faster
way
to
search
for emails with specific user defined ids?

Thanks

Regards
 
Back
Top