[英]How can I create group mail alias using office 365 API in C#
How can I create aliases for groups or specific e-mail accounts using the Office 365 API using C#?如何使用 C# 使用 Office 365 API 为组或特定电子邮件帐户创建别名?
I want to dynamically create a group alias name for a group (or specific email) that was already created in Office 365.我想为已在 Office 365 中创建的组(或特定电子邮件)动态创建组别名。
In this case, you can consider using the Microsoft Graph - Create Group在这种情况下,您可以考虑使用 Microsoft Graph - 创建组
First, ensure you have assigned the "Microsoft Graph" > "Read and write all groups" permission to app in Azure AD.首先,确保您已将“Microsoft Graph”>“读取和写入所有组”权限分配给 Azure AD 中的应用程序。
Code for your reference:代码供您参考:
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.