microsoftgraph/aspnet-snippets-sample

Issue with graph client accessing shared mailbox

batmanalien opened this issue · 3 comments

I have a shared mailbox that I want to read the inbox messages. I modified the GetMyInboxMessages method and got an Access Denied error, even if I have full access.

Any idea how to get this to work for my shared mailbox (where the user id is a GUID in the example below)?

public async Task<List<ResultsItem>> GetMyInboxMessages(GraphServiceClient graphClient) 
{
    List<ResultsItem> items = new List<ResultsItem>();

    IMailFolderMessagesCollectionPage messages = await graphClient
        .Users["0f4331c1-57c1-48b1-8374-edd4f58b8c73"]
        .MailFolders
        .Inbox
        .Messages
        .Request()
        .GetAsync();

    if (messages?.Count > 0) {
        foreach (Message message in messages) {
            items.Add(new ResultsItem {
                Display = message.Subject,
                    Id = message.Id
            });
        }
    }
    return items;
}

Were u able to resolve this ?

I know this is an old issue, but I wanted to post an answer anyway. In order for your code to work, you need two things:

  • The mailbox owner must have shared their mailbox with you
  • The app must request (and you must consent to) either Mail.Read.Shared or Mail.ReadWrite.Shared.

See https://docs.microsoft.com/graph/outlook-share-messages-folders