How to identify a mail item from a public folder in MS Outlook

D

DPM

Hi,

I have developed an application which read mails from a user selected folder
of MS Outlook.
Following is a code sample.

loOutlookSession = CREATEOBJECT("OutLook.Application")
loNameSpace = loOutlookSession.GetNameSpace("MAPI")
loMailFolder = loNameSpace.PickFolder()
IF loMailFolder.DefaultItemType = 0
** This is a folder with mail items
ENDIF

This works fine as long as a mail folder is selected but if the user selects
a public folder it does not imports its mails as the public folder's
DefaultItemType property returns 6.

I noticed that these public folders could have items other than mails, such
as tasks, contacts, ect..
Therefore even if public folders are allowed to import mails from it, it
fails when there are non mail items in the public folder.

To avoid this could someone please advice how to identify a mail item from
the rest of the non mail items in the public folder.
 
M

Michael Bauer [MVP - Outlook]

Instead of checking the folder's DefaultItemType property, you can check
each item's object type. For instance:

Dim obj as Object
For Each obj in Items
If Typeof obj is Outlook.MailItem Then ...
Next

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Tue, 10 Nov 2009 10:16:53 +0530 schrieb DPM:
 
J

JP

To add to what Michael wrote, use a custom function for this. i.e.

Function IsMailItem(Itm As Object) As Boolean
IsMailItem = (Typeof Itm is Outlook.MailItem)
End Function

Then call the function in your loop:

Dim obj as Object
For Each obj in Items
If IsMailItem(obj) Then ...

Next obj


--JP
 
J

JP

It's encapsulation, Michael. Besides, it's not going to change the
number of iterations.

--JP
 

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