Reputation: 31
I am using Graph API to delete emails. Below is the code. However I am unable to delete the emails permanently, since it can be recovered from "Recover Deleted Items from Server". Is any one aware of how to do this with the Graph API? Thank you.
user = ""
message_id = ""
query_url = url + "users/" + user + "/messages?$filter=internetMessageId eq '" + message_id + "'"
print(query_url)
bearer_token = "Bearer" + " " + token["access_token"]
headers = {'Authorization': bearer_token, 'Content-type':'application/json'}
response = requests.get(query_url, headers=headers, verify=False)
result = json.loads(response.text)
result_emails = result["value"]
for email in result_emails:
print email["sender"]["emailAddress"]["address"]
print email["subject"]
id = email["id"]
delete_url = url + "users/" + user + "/messages/" + id
print(delete_url)
response = requests.delete(delete_url, headers=headers, verify=False)
Upvotes: 3
Views: 6633
Reputation: 22032
When you hard delete a Message in Exchange (even with MFCMAPI) and you have Single Item Recovery turned on the message will end up in the Recoverable-items/purges folder see https://learn.microsoft.com/en-us/exchange/security-and-compliance/recoverable-items-folder/recoverable-items-folder. The only time its truly deleted is after the MFA (managed folder assistant) has done its work cycle.
So if you want to copy what a hard delete is doing you can just move the message to the purges folder which will make it invisible to the user and unrecoverable by a user (but an Admin could still recover it).
eg you can just use
POST https://graph.microsoft.com/v1.0/me/messages/AAMkADhAAATs28OAAA=/move
Content-type: application/json
{
"destinationId": "recoverableitemspurges"
}
Upvotes: 9