We have created a add-in for outlook to archive inactive emails to a harddrive location. It all works fine, except for e-mails that are not visible in the outlook folder because they are older than 6 months (or whatever setting they used).
Since it is not desirable to change the settings to show all e-mails on the server, I would rather try to set this in the plugin on folder level, or have another workaround to still copy e-mails that are not visible.
For i = 1 To NumberOfFolders
FolderTitle = objFolder.Folders(i).Name.ToString
FolderTitle = RemoveSpecialChars(FolderTitle)
Dim FolderPath As String
FolderPath = Link & FolderTitle & "\"
If Not System.IO.Directory.Exists(FolderPath) Then
MkDir(Link & FolderTitle)
End If
emailorder = 0
For Each Item In objFolder.Folders(i).Items
emailorder = emailorder + 1
Title = Strings.Right("000" & emailorder, 4) & " - " & RemoveSpecialChars(Item.Subject)
path = FolderPath & Title & ".msg"
Item.SaveAs(path)
ProgressValue = ProgressValue + 1
ProgressBarArchiving.Value = ProgressValue
Next
objFolder.Folders(i).Delete()
NumberOfFolders = objFolder.Folders.Count
If NumberOfFolders > 0 Then
i = 0
Else
MsgBox(ProgressValue & " e-mails archived")
Me.Close()
Exit Sub
End If
Next
So I am looking for a solution where I can find and copy the e-mails which are not visible in outlook for the user, or where I can make all e-mails visible on folder level to copy all of them without overloading the mailbox with a lot of old e-mails.
As a test I created the following (msgbox are just to see what happens:
Dim Session As RDOSession = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = app.Session.MAPIOBJECT
Dim store As RDOExchangeMailboxStore = Session.Stores.DefaultStore
Dim storeID As String = store.EntryID
MsgBox("StoreID: " & storeID)
Dim FolderTest As RDOFolder
FolderTest = Session.PickFolder()
Dim FolderTestID As String = FolderTest.EntryID
MsgBox("FolderTestID: " & FolderTestID)
Dim MAPI_NO_CACHE As Integer
'Dim MAPI_BEST_ACCESS As Integer
Dim FolderTest2 As RDOFolder = Session.GetFolderFromID(FolderTest.EntryID,, MAPI_NO_CACHE)
Dim NumItems As Long = FolderTest2.Items.Count
MsgBox("NumItems: " & NumItems)
For Each Item In FolderTest2.Items
MsgBox(Item.Subject)
Next