none
multiple mailboxes and the newMailEx event RRS feed

  • Question

  • Hi All

    I have a task before me that requires the monitoring of 3 mailboxes.  I have already verified that the newMailEx event is firing on all 3 mailboxes but the GetItemFromID() structure only has data in it when it is the "first" mailbox.  I do realize that I could use three itemadd events tied to the three mailboxes but I was wondering if it is possible to accomplish this using the newMailEx event for it does work well!  It is obvious that the Outlook Application knows what mailbox is receiving the new message and the newMailEx is an Application level event so surely there must be a way to extract the appropriate ID from the "application". Below is the code of the "main loop".  All of the dim statements are in and this does work for the "first" mailbox. Thanks in advance for your help.

        Set ns = Application.Session
        On Error Resume Next
        'Set fso = CreateObject("Scripting.FileSystemObject")
        arr = Split(EntryIDCollection, ",")
        For i = 0 To UBound(arr)
            Set m = ns.GetItemFromID(arr(i))
            If UCase(m.Subject) = "PHOTOS" Then
                Debug.Print "doing a photo copy"
                Set atth = m.Attachments
                atthCnt = atth.Count
                Debug.Print "attachment count is "; atthCnt
                If atthCnt > 0 Then
                   For j = atthCnt To 1 Step -1
                       atthFile = atth.Item(j).FileName
                       If InStr(1, atthFile, ".txt", vbTextCompare) > 0 Then
                          GoTo noimage
                       End If
                       fl = "c:\users\gordon2\documents\intrphotos\" + atthFile
                       Debug.Print "saving file "; fl
                       atth.Item(j).SaveAsFile fl
    noimage:
                   Next
                End If

                m.Delete
                Set m = Nothing
                Set atth = Nothing
            End If

    Respectfully,

    saahg


    Gordon Haas

    Saturday, April 4, 2015 8:31 PM

Answers

  • Hi Gordon,

    The Stores property of the Namespace class returns a Stores collection object that represents all the Store objects in the current profile. 

    Sub EnumerateFoldersInStores() 
     Dim colStores As Outlook.Stores 
     Dim oStore As Outlook.Store 
     Dim oRoot As Outlook.Folder 
     On Error Resume Next 
     Set colStores = Application.Session.Stores 
     For Each oStore In colStores 
      Set oRoot = oStore.GetRootFolder 
      Debug.Print (oRoot.FolderPath) 
      EnumerateFolders oRoot 
     Next 
    End Sub 

    The Store class provides the GetDefaultFolder method which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the  NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

    • Marked as answer by saahg Sunday, April 5, 2015 1:27 PM
    Sunday, April 5, 2015 7:16 AM

All replies

  • Hello Gordon,

    We had already discussed the same question on the Error when opening some Outlook MailItems with GetItemFromID using EntryID from Outlook Spy forum thread. Initialize all stores in the profile to make sure they were loaded correctly. You can simply iterate over stores to initialize them (i.e. touch them in any way). If not, you need to specify the second optional parameter explicitly.

    Also you may find the following articles helpful:

    Working with EntryIDs and StoreIDs

    Outlook NewMail event unleashed: the challenge (NewMail, NewMailEx, ItemAdd)

    Outlook NewMail event: solution options

    Outlook NewMail event and Extended MAPI: C# example

    Outlook NewMail unleashed: writing a working solution (C# example)


    Saturday, April 4, 2015 9:03 PM
  • Thanks for your reply Eugene.

    The problem with the solution identified in the discussion you referenced is the following:

     Set objFolder = ns.GetDefaultFolder(olFolderInbox)

    This references the first mailbox's inbox.  How do I set the objFolder to the second mailbox's inbox?

    The loop in the decision does indeed scan the inbox and do the job I need done in the first mailbox.  The problem still is when the second mailbox get's mail and cause the newMailEX event to fire the first mailbox's inbox is scanned.  Of course, I need the second inbox scanned when that mail arrives and the third when that mail arrives.

    Respectfully,

    saahg


    Gordon Haas

    Saturday, April 4, 2015 10:33 PM
  • Hi Gordon,

    The Stores property of the Namespace class returns a Stores collection object that represents all the Store objects in the current profile. 

    Sub EnumerateFoldersInStores() 
     Dim colStores As Outlook.Stores 
     Dim oStore As Outlook.Store 
     Dim oRoot As Outlook.Folder 
     On Error Resume Next 
     Set colStores = Application.Session.Stores 
     For Each oStore In colStores 
      Set oRoot = oStore.GetRootFolder 
      Debug.Print (oRoot.FolderPath) 
      EnumerateFolders oRoot 
     Next 
    End Sub 

    The Store class provides the GetDefaultFolder method which returns a Folder object that represents the default folder in the store and that is of the type specified by the FolderType argument. This method is similar to the GetDefaultFolder method of the  NameSpace object. The difference is that this method gets the default folder on the delivery store that is associated with the account, whereas NameSpace.GetDefaultFolder returns the default folder on the default store for the current profile.

    • Marked as answer by saahg Sunday, April 5, 2015 1:27 PM
    Sunday, April 5, 2015 7:16 AM
  • Yes Eugene I discovered the "Stores" architecture not too long after I sent the last thread extension.

    Again thanks for your help.  I think now I can come up with what I need to do.

    Respectfully,

    saahg


    Gordon Haas

    Sunday, April 5, 2015 1:33 PM