VSTO Outlook: Cannot find subfolders of shared inbox

断了今生、忘了曾经 提交于 2019-12-10 12:06:18

问题


I am trying to move mails from any folder to a very specific subfolder of a shared inbox. After trying many different things that did not work I tried to loop through every single folder in the inbox und check if it has the name I am looking for. When I try moving the mailitem, I get the message that the element could not be moved. After searching a little bit longer for the cause I found out, that apparently no folder inside of my inbox exist and the for each loop exits without checking a single entry. So how am I supposed to access a specific subfolder which i only know the name of?

Relevant code:

Private Const destFolder = "myfoldername"

Public Function MoveMail()
    SelectedItems = Globals.ThisAddIn.Application.ActiveExplorer.Selection
    For Each Item In SelectedItems
        Call MoveSelectedMail(Item)
    Next Item
End Function

Function MoveSelectedMail(Item As Outlook.MailItem)
    Item.Move(GetFolderToMove(destFolder))
End Function

Function GetFolderToMove(ByVal FolderName As String) As Outlook.Folder
    Dim NS As Outlook.NameSpace
    Dim objOwner As Outlook.Recipient
    NS = Globals.ThisAddIn.Application.GetNamespace("MAPI")
    objOwner = NS.CreateRecipient("NameofSharedMailbox")
    objOwner.Resolve()

    If objOwner.Resolved Then
        Dim inbox As Outlook.Folder
        inbox = NS.GetSharedDefaultFolder(objOwner, OlDefaultFolders.olFolderInbox)
        For Each folder As Outlook.Folder In inbox.Folders
            MsgBox(folder.Name)
            If folder.Name = FolderName Then
                Return folder
            End If
        Next folder
    End If
End Function

This is the code I used in VBA but did not work when I started trying to do the same thing as VSTO addin:

Function GetFolderToMove(ByVal FolderPath As String) As Outlook.Folder
    Dim NS As Outlook.NameSpace
    Dim objOwner As Outlook.Recipient
    Set NS = Application.GetNamespace("MAPI")
    Set objOwner = NS.CreateRecipient("NameofSharedMailbox")
    objOwner.Resolve

    If objOwner.Resolved Then
        Set GetFolderPath = NS.GetSharedDefaultFolder(objOwner, olFolderInbox).Folders(destFolder)
    End If
End Function

What I tried but did not help me solve this problem:

  • Tried returning only the shared inbox and this worked, however, the inbox is not the folder I want to move the mails to.

In short: I am trying to move a mail to a subfolder of a shared inbox but there seem to be no subfolders according to the error messages.

Hoping you can help me.

Edit: My Problem might be a little bit out of place as it seems that there might be a problem with the permissions my outlook account has. If the problem is going to be resolved that way, I will update this thread and close ist.


回答1:


I solved it - I am not entirely sure how exactly this could have happened but it certainly had to do with the permissions I had.



来源:https://stackoverflow.com/questions/40382371/vsto-outlook-cannot-find-subfolders-of-shared-inbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!