Oxygen
Oxygen

Reputation: 871

How to sent invitation email using Microsoft Graph API

I want to invite an user in our Active Directory/Tenant. For this using Micorosoft Graph API. Code is used as below

  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 = "[email protected]",
            InviteRedirectUrl = "https://myapp.com"
        };

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

After this, I can see the user in Azure's Active directory portal. But don't get an invitation email.

However, when I click on Resend Invite from Azure Portal then the invite email is coming.

Can you please guide, why the invite email is not coming when sending invite from API?

Upvotes: 2

Views: 4821

Answers (1)

Aman B
Aman B

Reputation: 2388

You need to set SendInvitationMessage to true in your Invitation object:

var invitation = new Invitation
        {
            InvitedUserEmailAddress = "[email protected]",
            InviteRedirectUrl = "https://myapp.com",
            SendInvitationMessage = true
        };

For more info you can read the Docs

sendInvitationMessage Boolean Indicates whether an email should be sent to the user being invited or not. The default is false.

Upvotes: 6

Related Questions