Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Moving emails to Deleted Items using Microsoft Graph API

I would like to delete emails in the mailbox of a specific account using C# .NET Microsoft Graph API.

I have seen posts suggesting the DeleteAsync() method, but this permanently deletes the item. Is there a way to delete the email so that it will be moved to the Deleted Items folder instead of being completely unrecoverable?

foreach (Microsoft.Graph.Message currMessage in emails)
{
    string msgId = currMessage.Id;
    string sender = currMessage.From.EmailAddress.Address.ToString();
    string subejct = currMessage.Subject;
    string receivedDate = currMessage.ReceivedDateTime.Value.ToLocalTime().ToString("dd/MM/yyyy hh:mm tt");

    await graphClient.Users[emailUser]
        .Messages[msgId]
        .Request()
        .DeleteAsync();
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In SDK v5, you can move message to deleted items this way:

using Microsoft.Graph.Me.Messages.Item.Move;

var requestBody = new MovePostRequestBody
{
    DestinationId = "deletedItems",
};

var result = await graphClient.Users[emailUser].Messages["{message-id}"].Move.PostAsync(requestBody);

For SDK v4, it’s a little bit different:

var result = await graphClient.Users[emailUser].Messages["{message-id}"].Move("deletedItems").Request().PostAsync();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading