Hi, my workflow is required to check if a list of Outlook folders exists in the local outlook email account. I have achieved this using the following assigns.
OutlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass
OutlookFolders = OutlookApp.Session.DefaultStore.GetRootFolder().Folders
I then call a Get Outlook Message Activity in a Try Catch, with the Folder Property as one of the folders from the list. If an Argument Exception: “The specified folder is not found” is thrown, I then create the folder using this assign:
But lets say I have 3 outlook accounts in my Outlook App, if i want to do this with another account instead of the default account, how do i go about doing this?
=> Create Variable: First, create a variable to hold the account address you want to work with. Let’s call it accountAddress.
=> Use the Specified Account: Replace your existing code with the following modified version:
OutlookApp = new Microsoft.Office.Interop.Outlook.ApplicationClass;
OutlookNamespace = OutlookApp.GetNamespace("MAPI");
// Here, use the 'accountAddress' variable to specify the desired account
OutlookNamespace.Logon("user1@outlook.com", "YourPassword", Missing.Value, Missing.Value);
OutlookFolders = OutlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Folders;
// Perform your folder checks and creation here
OutlookNamespace.Logoff();
In this code, replace "user1@outlook.com" with the accountAddress variable. This will allow you to dynamically choose which Outlook account’s folders you want to interact with based on the input you provide.
=> Loop Through Accounts (Optional): If you have multiple accounts and want to loop through them, you can create a list of account addresses and loop through them, applying the same set of operations to each account.