如何在 C# 中使用 office 365 API 创建群组邮件别名
How can I create group mail alias using office 365 API in C#
如何使用 C# 使用 Office 365 API 为组或特定电子邮件帐户创建别名?
我想为已在 Office 365 中创建的组(或特定电子邮件)动态创建组别名。
这种情况下,可以考虑使用Microsoft Graph - Create Group
首先,确保您已将 "Microsoft Graph" > "Read and write all groups" 权限分配给 Azure AD 中的应用程序。
供您参考的代码:
string authority = "https://login.windows.net/yourdomain.onmicrosoft.com";
string clientId = "{client_id}";
Uri redirectUri = new Uri("http://localhost");
string resourceUrl = "https://graph.microsoft.com";
HttpClient client = new HttpClient();
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resourceUrl,
clientId, redirectUri, PromptBehavior.Always);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + authenticationResult.AccessToken);
string content = @"{
'displayName': 'mailgrouptest',
'groupTypes': ['Unified'],
'mailEnabled': true,
'mailNickname': 'mailalias1',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
如何使用 C# 使用 Office 365 API 为组或特定电子邮件帐户创建别名?
我想为已在 Office 365 中创建的组(或特定电子邮件)动态创建组别名。
这种情况下,可以考虑使用Microsoft Graph - Create Group
首先,确保您已将 "Microsoft Graph" > "Read and write all groups" 权限分配给 Azure AD 中的应用程序。
供您参考的代码:
string authority = "https://login.windows.net/yourdomain.onmicrosoft.com";
string clientId = "{client_id}";
Uri redirectUri = new Uri("http://localhost");
string resourceUrl = "https://graph.microsoft.com";
HttpClient client = new HttpClient();
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resourceUrl,
clientId, redirectUri, PromptBehavior.Always);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + authenticationResult.AccessToken);
string content = @"{
'displayName': 'mailgrouptest',
'groupTypes': ['Unified'],
'mailEnabled': true,
'mailNickname': 'mailalias1',
'securityEnabled': false
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/groups", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);