使用User.Invite.All权限通过Graph SDK for C#邀AAD用户能否指定发件邮箱?
Can I specify a custom sender email for AAD user invitations via Microsoft Graph SDK for C#?
Great question! The short answer is yes, this is absolutely feasible—but there are a few key requirements and implementation details you need to keep in mind to pull this off.
Key Prerequisites
Before you can set a custom sender, make sure you have these covered:
- You already have the
User.Invite.Allapplication permission (good job on that!) but you'll also need theMail.Sendapplication permission added to your registered app, with admin consent granted. This allows your app to send emails on behalf of the specified sender. - The sender email address you want to use must be a valid, active user within your Azure AD tenant—you can't use external addresses or Microsoft's default noreply addresses here.
Implementation with C# Graph SDK
Here's a concrete code example showing how to specify the custom sender when creating an invitation:
using Microsoft.Graph; using Microsoft.Graph.Models; using Azure.Identity; // Initialize Graph client with application permissions var scopes = new[] { "https://graph.microsoft.com/.default" }; var clientSecretCredential = new ClientSecretCredential( "your-tenant-id", "your-client-id", "your-client-secret"); var graphClient = new GraphServiceClient(clientSecretCredential, scopes); // Build the invitation request with custom sender var invitation = new Invitation { InvitedUserEmailAddress = "external-collaborator@example.com", InvitedUserDisplayName = "Jane Doe", InviteRedirectUrl = "https://your-app-dashboard.com", // Where the user lands after accepting SendInvitationMessage = true, InvitedUserMessageInfo = new InvitedUserMessageInfo { Subject = "You're invited to join our organization!", Body = "Hi Jane, please click the link below to join our Azure AD tenant and access our resources.", // Specify your custom sender here Sender = new Recipient { EmailAddress = new EmailAddress { Address = "internal-sender@yourtenant.com" } } } }; // Send the invitation var createdInvitation = await graphClient.Invitations.PostAsync(invitation);
Important Notes
- If you omit the
Senderproperty, the invitation will default to sending from Microsoft's noreply address (e.g.,no-reply@microsoft.com). - Double-check that your tenant's email flow rules don't block messages sent by your app on behalf of the specified sender—some organizations have strict policies here.
- The
InvitedUserMessageInfoobject also lets you customize the email subject, body, and even add attachments if needed.
That's all! As long as you meet the permission and sender validity requirements, you'll be able to send invitations from your desired email address.
内容的提问来源于stack exchange,提问作者MJ Schanne
相关产品推荐
相关产品推荐

