You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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.All application permission (good job on that!) but you'll also need the Mail.Send application 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 Sender property, 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 InvitedUserMessageInfo object 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 17:22:53