HighlanderSword

Outlook Search Folders

12 posts in this topic

Hello,

I'm attempting to get the Store id and the Entry id of various Search folders in Outlook 2013.

I'm able to manually get them by selecting them and the running the code below

and I get the result of

\\Paul Schrader 2012\search folders\Mail to Read

 

When I change the _ol_folderget to

_OL_FolderGet($oOutlook,"\\Paul Schrader 2012\search folders\Mail to Read")

_OL_FolderGet($oOutlook,"Paul Schrader 2012\search folders\Mail to Read")

_OL_FolderGet($oOutlook,"Paul Schrader 2012\search folders\Mail to Read\")

I get error messages of @error=1 and extended = 4. I need to get this information for over 400 Search folders.

 

What am I missing ?

 

#include <OutlookEX.au3>

Global $oOutlook = _OL_Open()

Global $SrchFolder = _OL_FolderGet($oOutlook)

_ArrayDisplay($Srchfolder)

 

 

 

 

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The UDF does not support search folders. You need to use something like this:

#include <OutlookEX.au3>

Global $oOL = _OL_Open()
Global $oNamespace = $oOL.GetNamespace("MAPI")
Global $oDefaultStore = $oNamespace.DefaultStore
Global $oSearchFolders = $oDefaultStore.GetSearchFolders
Global $oSearchFolder = $oSearchFolders("Mail to Read")

;-------------------------------------
; Get all mails from the search folder
;-------------------------------------
Global $aItems = _OL_ItemFind($oOL, $oSearchFolder, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems, "Unread mails")

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank, The information you provided worked

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Hello,

I'm trying to get the email count from 3 search folders (on 3 different mailboxes).  I'm still really new to this, so I figured that if I repeat the steps for each mailbox, I would get 3 different results.  Here's my code:

Global $oOL = _OL_Open()
Global $oNamespace = $oOL.GetNamespace("MAPI")
Global $oDefaultStore = $oNamespace.DefaultStore ; Access the default store
Global $oSearchFolders = $oDefaultStore.GetSearchFolders ; Access the collection of search folders
Global $oSearchFolder = $oSearchFolders("Unreplied") ; Access the search folder named "Mail to Read"


;-------------------------------------
; Get all mails from the search folder1
;-------------------------------------
Global $aItems = _OL_ItemFind($oOL, $oSearchFolder, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems, "Unreplied mails")



Global $oOL2 = _OL_Open()
Global $oNamespace2 = $oOL2.GetNamespace("MAPI")
Global $oDefaultStore2 = $oNamespace2.DefaultStore ; Access the default store
Global $oSearchFolders2 = $oDefaultStore2.GetSearchFolders ; Access the collection of search folders
Global $oSearchFolder2 = $oSearchFolders2("Unreplied2") ; Access the search folder named "Mail to Read"


;-------------------------------------
; Get all mails from the search folder2
;-------------------------------------
Global $aItems2 = _OL_ItemFind($oOL2, $oSearchFolder2, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems2, "Unreplied mails")



Global $oOL3 = _OL_Open()
Global $oNamespace3 = $oOL3.GetNamespace("MAPI")
Global $oDefaultStore3 = $oNamespace3.DefaultStore ; Access the default store
Global $oSearchFolders3 = $oDefaultStore3.GetSearchFolders ; Access the collection of search folders
Global $oSearchFolder3 = $oSearchFolders3("Unreplied3") ; Access the search folder named "Mail to Read"


;-------------------------------------
; Get all mails from the search folder2
;-------------------------------------
Global $aItems3 = _OL_ItemFind($oOL3, $oSearchFolder3, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems3, "Unreplied mails")

The first one comes up ok.  But the rest won't display the results.  Is there another way of doing this?

Thanks in advance!!

Share this post


Link to post
Share on other sites

You do not need to multiply the whole code. This stripped down version should do the trick as well (untested):

#include <OutlookEX.au3>
Global $oOL = _OL_Open()
Global $oNamespace = $oOL.GetNamespace("MAPI")
Global $oDefaultStore = $oNamespace.DefaultStore ; Access the default store
Global $oSearchFolders = $oDefaultStore.GetSearchFolders ; Access the collection of search folders
Global $oSearchFolder1 = $oSearchFolders("Unreplied") ; Access the search folder named "Mail to Read"

;-------------------------------------
; Get all mails from the search folder1
;-------------------------------------
Global $aItems = _OL_ItemFind($oOL, $oSearchFolder1, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems, "Unreplied mails")

; Global $oOL2 = _OL_Open()
; Global $oNamespace2 = $oOL2.GetNamespace("MAPI")
; Global $oDefaultStore2 = $oNamespace2.DefaultStore ; Access the default store
; Global $oSearchFolders2 = $oDefaultStore2.GetSearchFolders ; Access the collection of search folders
Global $oSearchFolder2 = $oSearchFolders("Unreplied2") ; Access the search folder named "Mail to Read"

;-------------------------------------
; Get all mails from the search folder2
;-------------------------------------
Global $aItems2 = _OL_ItemFind($oOL, $oSearchFolder2, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems2, "Unreplied mails")

; Global $oOL3 = _OL_Open()
; Global $oNamespace3 = $oOL3.GetNamespace("MAPI")
; Global $oDefaultStore3 = $oNamespace3.DefaultStore ; Access the default store
; Global $oSearchFolders3 = $oDefaultStore3.GetSearchFolders ; Access the collection of search folders
Global $oSearchFolder3 = $oSearchFolders("Unreplied3") ; Access the search folder named "Mail to Read"

;-------------------------------------
; Get all mails from the search folder2
;-------------------------------------
Global $aItems3 = _OL_ItemFind($oOL, $oSearchFolder3, $olMail, "", "", "", "Subject,Body")
_ArrayDisplay($aItems3, "Unreplied mails")

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks water!  But it still doesn't show the results for the 2nd and 3rd search folders.  I'm thinking I might have missed indicating the mailbox name?  Not sure where to put it though.

Share this post


Link to post
Share on other sites

So you checking 3 search folders in 3 different stores (Mailboxes)?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

yup!  3 search folders in 3 different mailboxes (1 search folder each mailbox).

Share this post


Link to post
Share on other sites

#10 ·  Posted

As a start. This little script lists all search folders in all accessed stores:

#include <OutlookEX.au3>
Global $oOL = _OL_Open()
Global $oStores = $oOL.Session.Stores
ConsoleWrite("Store count: " & $oStores.Count & @CRLF)
For $i = 1 To $oStores.Count
    $oStore = $oStores($i)
    ConsoleWrite("Store " & $i & ": Displayname: " & $oStore.DisplayName & ", FilePath: " & $oStore.FilePath & @CRLF)
    $oSearchFolders = $oStore.GetSearchFolders
    For $oSearchFolder In $oSearchFolders
        ConsoleWrite("  SearchFolder: " & $oSearchFolder.FolderPath & @CRLF)
    Next
Next

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

Not sure how this one stayed so long in the Examples forum. Moved to the appropriate forum.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
18 hours ago, water said:

As a start. This little script lists all search folders in all accessed stores:

#include <OutlookEX.au3>
Global $oOL = _OL_Open()
Global $oStores = $oOL.Session.Stores
ConsoleWrite("Store count: " & $oStores.Count & @CRLF)
For $i = 1 To $oStores.Count
    $oStore = $oStores($i)
    ConsoleWrite("Store " & $i & ": Displayname: " & $oStore.DisplayName & ", FilePath: " & $oStore.FilePath & @CRLF)
    $oSearchFolders = $oStore.GetSearchFolders
    For $oSearchFolder In $oSearchFolders
        ConsoleWrite("  SearchFolder: " & $oSearchFolder.FolderPath & @CRLF)
    Next
Next

 

Thanks water!  I'll play around with it for a while.  I'll update you with the result.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now