Search code examples
c#microsoft-graph-api

How to move emails between folders in the shared email boxes via Graph API using C#


Currently I have this Microsoft.Graph.Models.Message object, using this object how can I move messages from one folder to another?


Solution

  • You need to use the Move Endpoint which take the messageId of the Message your trying to move and the folderId of the folder you want to move it to.With Shared Mailboxes depending on the Auth model your using (Delegate or Application) your generally better of getting the actual folderId of the Target folder rather then using the wellknownfolder enum https://learn.microsoft.com/en-us/graph/api/user-list-mailfolders?view=graph-rest-1.0&tabs=http. then you can do something like

    using Microsoft.Graph.Users.Item.Messages.Item.Move
    
    var requestBody = new MovePostRequestBody
    {
        DestinationId = "{Target-folderid}",
    };
    
    var result = await graphClient.Users[{sharedMailboxid}].Messages["{message-id}"].Move.PostAsync(requestBody);