So I have an add in that monitors the sent items folder and uploads emails to an azure storage when a new item hits it, if it meets certain criteria. my issue is that it only works on the default account sent items. i need it to look at all the sent items. eg i have 3 accounts in outlook but it only works on the main account. this is the code that works for the default items:
Dim sentItems As Outlook.Items
Dim sentFolder As Outlook.Folder
Dim oApp As New Outlook.Application
sentFolder = oApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail)
sentItems = sentFolder.Items
AddHandler sentItems.ItemAdd, AddressOf itemadd
where "itemadd" is the function that does the upload work.
what i attempted to get it to do all the folders is
Dim sentfolders As List(Of Outlook.Folder)
Dim sentitemslist As List(Of Outlook.Items)
Dim oApp As New Outlook.Application
Dim accounts As Outlook.Accounts = oApp.Session.Accounts
Dim account As Outlook.Account
Dim i As Integer = 0
For Each account In accounts
sentfolders(i) = account.CurrentUser.Session.Folders(Outlook.OlDefaultFolders.olFolderSentMail) **
sentitemslist(i) = sentfolders(i).Items
AddHandler sentitemslist(i).ItemAdd, AddressOf itemadd
Next
which gives me a 'Object reference not set to an instance of an object.' error on the line marked with **. ive tried various other things on that line to no avail.