How to delete mail as Admin

Occasional Contributor

Hi All,


I am new to O365.

I am creating a phishing mail detection solution for O365. At final stage I want to purge the mail using admin credentials through java API. 


Can you please redirect me to correct page where I can get some inputs?






2 Replies

Hello @pranjal sharma,

I know you are asking about API/code way to do this, but i did not have much luck finding that. In an effort to give you more information that may help your search, I wanted to give you the steps to do this in O365, and hopefully that can help you figure out if there are API ways to do this.


To delete a message in O365, its actually a multi-step process through the security and compliance center. (you also need a specific permission granted to do this, ediscovery admin)


1. Create a content search in O365 for the data in question. (based on your search and tenant size this can take anywhere from a min or two, to significantly longer).

2. Login to the Security and Compliance center on O365 via powershell

3. Delete the message through powershell


Here is the detailed steps -

I tried to find the graph API commands to correlate to this, and did not have much luck. Maybe having the steps of what you need to do as an admin can help you in your research to find the API commands. Goodluck!



Thanks Adam,

Actually I am using cmdlet Search-mailbox currently but this makes my code OS and powershell dependent, so I am looking for other option. Graph APIs I tried but not able to succeed in achieving the same.