【问题标题】:How to sent invitation email using Microsoft Graph API如何使用 Microsoft Graph API 发送邀请电子邮件
【发布时间】:2019-10-03 18:14:33
【问题描述】:

我想邀请我们的 Active Directory/租户中的用户。为此使用 Mirosoft Graph API。代码使用如下

  IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
            .Create(clientId)
            .WithTenantId(tenantID)
            .WithClientSecret(clientSecret)
            .Build();

        ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

        GraphServiceClient graphClient = new GraphServiceClient(authProvider);

        var invitation = new Invitation
        {
            InvitedUserEmailAddress = "myemailaddress@gmail.com",
            InviteRedirectUrl = "https://myapp.com"
        };

        await graphClient.Invitations
            .Request()
            .AddAsync(invitation);

之后,我可以在 Azure 的 Active Directory 门户中看到该用户。但不要收到邀请电子邮件。

但是,当我从 Azure 门户点击 Resend Invite 时,就会收到邀请电子邮件。

您能否指导一下,为什么从 API 发送邀请时没有收到邀请电子邮件?

【问题讨论】:

    标签: c# azure-active-directory microsoft-graph-api microsoft-graph-sdks


    【解决方案1】:

    您需要在Invitation 对象中将SendInvitationMessage 设置为true

    var invitation = new Invitation
            {
                InvitedUserEmailAddress = "myemailaddress@gmail.com",
                InviteRedirectUrl = "https://myapp.com",
                SendInvitationMessage = true
            };
    

    有关更多信息,您可以阅读Docs

    sendInvitationMessage Boolean 指示是否应发送电子邮件 是否发送给被邀请的用户。默认为假。

    【讨论】:

    • 感谢您的帮助。小q,这可能与本帖无关。我们如何使用图形 API 确认用户已接受邀请?
    • @Oxygen 用户 API 的 beta 版本返回一个名为 externalUserState 的字段,如果用户尚未兑换邀请,该字段的值将为 PendingAcceptance。看看这个uservoice
    • @NateJackson。看不到用户的这个属性。我正在使用 Microsoft Graph SDK 的 1.17.0.0 版本。代码是 var user = await graphClient.Users["{userPrinciplename}"].Request().GetAsync();返回 Convert.ToBoolean(user.ExternalUserState); // 没有属性 ExternalUserState。能指导一下吗?
    • @Oxygen 正如我的评论所说,BETA API 有这些字段。 here are the docs
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 2021-12-05
    • 2018-03-18
    相关资源
    最近更新 更多