包信息
| 属性 | 值 |
|---|---|
| NuGet 包 | Bitzsoft.Integrations.EnterpriseMail.Microsoft365 |
| Provider ID | microsoft365 |
| 鉴权 | OAuth 2.0 client_credentials(Azure AD TenantId + ClientId + ClientSecret) |
| 生命周期 | Transient |
配置字段(Microsoft365MailOptions)
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
TenantId | string | 是 | — | Azure AD 租户标识 |
ClientId | string | 是 | — | Azure AD 应用客户端标识 |
ClientSecret | string | 是 | — | Azure AD 应用客户端密钥 |
DefaultUserEmail | string | 否 | — | 默认操作的邮箱地址 |
BaseUrl | string | 否 | https://graph.microsoft.com/v1.0 | Graph API 基地址 |
TokenEndpoint | string | 否 | https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token | 令牌端点模板 |
HttpClientName | string | 否 | Microsoft365Mail | 旧版兼容字段(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字段仅为配置绑定兼容保留。
相关
- 企业邮箱域手册:接口设计