问题
Is it possible for me to access everyone emails within my company using the Office 365 Mail API? I know I can access individuals, but hat requires me to be granted access to their emails and get their access tokens. I would like to be able to have an admin access token and be able to access everyone's emails. Any ideas whether this is possible or not?
回答1:
It is possible. We can register a Web application and/or Web API (default, known as a confidential client in OAuth2 parlance) an build a daemon service to retrieve all the messages for organization.
Here is an example that using the client credentials to request the token and get the messages from different users:
string authority = "https://login.microsoftonline.com/msdnofficedev.onmicrosoft.com";
string resource = "https://Graph.microsoft.com";
string clientID = "";
string clientSecret = "";
AuthenticationContext ac = new AuthenticationContext(authority);
AuthenticationResult ar = ac.AcquireToken(resource, new ClientCredential(clientID, clientSecret));
HttpClient hc = new HttpClient();
hc.DefaultRequestHeaders.Add("Authorization", "Bearer " + ar.AccessToken);
HttpResponseMessage hrm = await hc.GetAsync("https://Graph.microsoft.com/v1.0/users/fx@msdnofficedev.onmicrosoft.com/messages/");
string content=await hrm.Content.ReadAsStringAsync();
MessageBox.Show(content);
HttpResponseMessage hrm2 = await hc.GetAsync("https://Graph.microsoft.com/v1.0/users/user1@msdnofficedev.onmicrosoft.com/messages/");
content = await hrm2.Content.ReadAsStringAsync();
MessageBox.Show(content);
For more detail about register application in Azure AD, you can follow link below: https://azure.microsoft.com/en-us/documentation/articles/active-directory-integrating-applications/#BKMK_Native
来源:https://stackoverflow.com/questions/36121571/office-365-mail-api-admin-access-token-to-access-everyones-emails