使用microsoft graph api删除共享邮箱的电子邮件


import msal
from office365.graph_client import GraphClient
import json
import requests
import urllib3
authority_url = 'https://login.microsoftonline.com/ae4df1f7-611e-444f-897e-f964e1205171'
authority=authority_url,
app = msal.ConfidentialClientApplication(
client_id = '------',
client_credential = '-----'
)
token = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
data = json.dumps(token)
dict1= json.loads(data)
token_value = dict1["access_token"]   ##Able to obtain the token
url = 'https://graph.microsoft.com/v1.0/users/sharedmailbox@xyz.com/mailFolders/Inbox/messages/59f3b86064fc4590969f468bbffe323c@MW4PR15MB3453.namprd15.prod.outlook.com'
headers = {
'authorization': "Bearer " + token_value,
}
response = requests.delete(url, headers=headers)
print(response)

我得到<响应[400]>请帮忙!!!!!!!!!!!参考:https://learn.microsoft.com/en-us/graph/api/message-delete?view=graph-rest-1.0&tabs=http应用程序权限邮件。ReadWrite是给定的,但它仍然不起作用。不过,我可以读取数据,这很好。**

从行

url = 'https://graph.microsoft.com/v1.0/users/sharedmailbox@xyz.com/mailFolders/Inbox/messages/59f3b86064fc4590969f468bbffe323c@MW4PR15MB3453.namprd15.prod.outlook.com

看起来你试图使用InternetMessageId来删除消息,但这不起作用,你需要找到基础ItemId(即Exchange Mid(。如果你只有InternetMessageId,那么首先使用过滤器来找到它,例如

https://graph.microsoft.com/v1.0/users/sharedmailbox@xyz.com/mailFolders/Inbox/messages/$filter=internetMessageId eq '%3C59f3b86064fc4590969f468bbffe323c%40MW4PR15MB3453.namprd15.prod.outlook.com%3E'

InternetMessageId(无论如何都是来自Office365的消息(总是包含在<gt;所以你需要包含然后逃离它。您需要获取搜索返回的Base64 id属性,然后使用该属性。

最新更新