Skip to content
Bitzsoft.Integrationsbitzsoft.integrations

Reference

Microsoft 365 邮箱

Microsoft 365 企业邮箱包的 Microsoft365MailOptions 配置字段、Graph API client_credentials 流与使用示例。

Last updated

包信息

属性
NuGet 包Bitzsoft.Integrations.EnterpriseMail.Microsoft365
Provider IDmicrosoft365
鉴权OAuth 2.0 client_credentials(Azure AD TenantId + ClientId + ClientSecret)
生命周期Transient

配置字段(Microsoft365MailOptions)

字段类型必填默认值说明
TenantIdstringAzure AD 租户标识
ClientIdstringAzure AD 应用客户端标识
ClientSecretstringAzure AD 应用客户端密钥
DefaultUserEmailstring默认操作的邮箱地址
BaseUrlstringhttps://graph.microsoft.com/v1.0Graph API 基地址
TokenEndpointstringhttps://login.microsoftonline.com/{tenant}/oauth2/v2.0/token令牌端点模板
HttpClientNamestringMicrosoft365Mail旧版兼容字段(Graph transport 不读取)

配置示例

{
"EnterpriseMail": {
"Microsoft365": {
"TenantId": "your-tenant-id",
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret",
"DefaultUserEmail": "user@your-domain.com"
}
}
}

DI 注册

// ① 配置节绑定
builder.Services.AddBitzsoftMicrosoft365Mail(builder.Configuration.GetSection("EnterpriseMail:Microsoft365"));
// ② 委托配置
builder.Services.AddBitzsoftMicrosoft365Mail(options =>
{
options.TenantId = "your-tenant-id";
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret";
options.DefaultUserEmail = "user@your-domain.com";
});

使用示例

public class GraphMailService(IEnterpriseMailProvider mail)
{
public async Task<Stream> DownloadAttachmentAsync(string messageId, string attachmentId)
{
return await mail.DownloadAttachmentAsync(messageId, attachmentId);
}
public async Task MoveAsync(string messageId, string targetFolderId)
{
await mail.MoveMessageAsync(messageId, targetFolderId);
}
}

已知限制

  • TokenEndpoint 使用 {tenant} 占位符,运行时替换为 TenantId
  • 共享 Microsoft Graph transport,HttpClientName 字段仅为配置绑定兼容保留。

相关

100%

滚轮或按钮缩放 · 放大后拖动画面 · 双击切换 100% / 200%