通过Office 365 REST API访问所有用户的邮箱 [英] Accessing all user's mailbox via Office 365 REST API

查看:270
本文介绍了通过Office 365 REST API访问所有用户的邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试Office 365 Rest API.

I am trying out Office 365 Rest APIs.

  • 我已经在Azure AD中注册了应用程序.
  • 已设置以下权限:Exchange:访问所有用户的邮箱,对用户日历的完全控制,对用户联系人的完全控制,对用户邮箱的完全控制
  • 我已经生成了具有管理员权限的访问令牌,该令牌具有全局管理员权限.
  • 发送以下请求' https://outlook.office365.com/api/users/我/邮件",结果正确无误,从而为我提供了当前管理员邮箱中的所有邮件
  • 发送以下请求' https://outlook.office365.com/api/users/ {另一个用户的电子邮件}/消息".这导致以下错误

  • I have registered application with Azure AD.
  • It has following permission set: Exchange: Access All User's Mailbox, Full Control on User's Calendar, Full Control on User's Contacts, Full Control on User's Mailbox
  • I have generated access token with admin grant which has global admin privileges.
  • Sent following request 'https://outlook.office365.com/api/users/me/messages' which resulted in correct results giving me all messages in current admin's mailbox
  • Sent following request 'https://outlook.office365.com/api/users/{another user's email}/messages'. This resulted in following error

"u'错误":{u'消息:u'访问被拒绝.请检查凭据,然后重试.',u'code':u'ErrorAccessDenied'}}"

"u'error': {u'message': u'Access is denied. Check credentials and try again.', u'code': u'ErrorAccessDenied'}}"

如果以上步骤有误,请告诉我?

Please let me know if above steps are wrong ?

如果输入错误,是否有办法从其他用户的邮箱中获取电子邮件,因为我具有管理员凭据?

If they are wrong, is there a way to fetch emails from another user's mailbox as I have admin credentials ?

谢谢.

推荐答案

您需要使用此

You need to use a service account as described in this blog, for your scenario and the app will be able to make calls to interact with any mailboxes in that tenant. The reason your request to use another user's mailbox is failing is because the request will be approved only if the app and user have permissions to access the other user's mailbox. In your case, the admin has permissions to the other user's mailbox. But the app, assuming you used OAuth code flow, to get the OAuth token, only has permissions to the authenticated user's mailbox.

此外,您不需要REST API的访问所有用户的邮箱"权限,因为它们用于使用Exchange Web服务(EWS)SOAP API.

Also, you don't need "Access All User's Mailbox" permissions for REST APIs, as they are meant for using Exchange Web Services (EWS) SOAP APIs.

这篇关于通过Office 365 REST API访问所有用户的邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆