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

如何通过微软工具获取Outlook邮件敏感度并适配跨端加载项

解决方案:获取Outlook邮件敏感度并控制插件操作

针对你遇到的Windows/Mac跨端Outlook插件行为差异,以及无法获取邮件敏感度的问题,提供以下可行方案:

一、通过Office.js扩展属性获取敏感度(适用于MailItem)

你之前的代码仅针对Appointment,对于邮件(MailItem),需要通过MAPI扩展属性PR_SENSITIVITY(属性ID:0x0036,类型为Integer)来获取敏感度值。以下是适配TypeScript/Angular的代码:

// 获取邮件敏感度的MAPI扩展属性
getMailSensitivity(): void {
  Office.context.mailbox.item.getExtendedPropertiesAsync(
    [{ propertyId: "Integer 0x0036" }],
    (asyncResult) => {
      if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
        const sensitivityValue = asyncResult.value[0].value;
        // 敏感度值对应映射:
        // 0 = Normal(正常), 1 = Personal(个人), 2 = Private(私有), 3 = Confidential(机密)
        switch (sensitivityValue) {
          case 0:
          case 1:
            console.log("邮件敏感度:正常/个人");
            this.toggleSensitiveActions(false);
            break;
          case 2:
          case 3:
            console.log("邮件敏感度:私有/机密");
            this.toggleSensitiveActions(true);
            break;
        }
      } else {
        console.error("获取敏感度失败:", asyncResult.error);
      }
    }
  );
}

// 根据敏感度禁用/启用插件操作
toggleSensitiveActions(isSensitive: boolean): void {
  // Angular中可绑定变量控制组件状态
  this.isSensitiveMail = isSensitive;
  // 示例:禁用特定操作按钮
  document.getElementById('sensitive-action-btn')?.setAttribute('disabled', isSensitive.toString());
}

二、通过Microsoft Graph API获取邮件敏感度

如果Office.js的扩展属性方式在Mac端存在限制,可以调用Graph API获取完整邮件信息,其中sensitivity字段直接返回枚举值(Normal/Personal/Private/Confidential)。

步骤1:配置插件权限

在插件清单文件(manifest.xml)中声明必要权限:

<Permissions>ReadWriteMailbox</Permissions>

步骤2:Angular中调用Graph API代码示例

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

@Injectable()
export class MailService {
  constructor(private http: HttpClient) {}

  getMailSensitivity(mailId: string): void {
    // 获取Graph API访问令牌
    Office.context.auth.getAccessTokenAsync({
      allowConsentPrompt: true,
      forMSGraphAccess: true
    }, (tokenResult) => {
      if (tokenResult.status === Office.AsyncResultStatus.Succeeded) {
        const accessToken = tokenResult.value;
        this.http.get(`https://graph.microsoft.com/v1.0/me/messages/${mailId}`, {
          headers: { Authorization: `Bearer ${accessToken}` }
        }).subscribe((mail: any) => {
          const sensitivity = mail.sensitivity;
          console.log("邮件敏感度:", sensitivity);
          // 根据敏感度控制操作
          this.toggleSensitiveActions(['Private', 'Confidential'].includes(sensitivity));
        }, (error) => {
          console.error("调用Graph API失败:", error);
        });
      } else {
        console.error("获取访问令牌失败:", tokenResult.error);
      }
    });
  }
}

// 在组件中调用
const currentMailId = Office.context.mailbox.item.itemId;
this.mailService.getMailSensitivity(currentMailId);

三、解决Mac端插件自动禁用问题

Mac端Outlook对敏感邮件的插件禁用可能是默认策略,可通过以下方式处理:

  • 更新Outlook版本:确保Mac端Outlook为最新稳定版,预览版可能存在兼容性问题;
  • 清单文件配置:在manifest.xml的<Requirements>节点中指定支持的最低Office版本,确保API兼容性:
<Requirements>
  <Sets DefaultMinVersion="1.10">
    <Set Name="Mailbox" MinVersion="1.10"/>
  </Sets>
</Requirements>
  • 检查系统权限:在Mac端Outlook的「偏好设置」>「隐私与安全性」中,确认插件被允许访问敏感内容。

注意事项

  • 可通过Office.context.requirements.isSetSupported('Mailbox', '1.10')检查当前环境是否支持扩展属性操作;
  • 使用Graph API需在Azure AD中注册应用,并配置正确的API权限(如Mail.Read);
  • 测试时覆盖所有敏感度类型的邮件,确保跨端行为一致。

内容的提问来源于stack exchange,提问作者Ramesh Kumar Palagara

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 08:55:17