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

如何用Exchange Web Service API获取Outlook的Focused/Other标签邮件

使用EWS获取Outlook Focused标签邮件的实现方法

EWS(Exchange Web Service)支持通过扩展属性识别Outlook的Focused/Other分类,对应Graph API里的inferenceClassification逻辑,具体实现如下:

核心逻辑

Exchange 2013及以后版本支持邮件智能分类标记,该标记存储在一个标准扩展属性中:

  • Focused标签对应属性值为0
  • Other标签对应属性值为1

需要手动定义该扩展属性,并添加过滤条件筛选目标邮件。

修正后的完整代码

先修正你代码中的两处问题:将Exchange版本改为Exchange2013(智能分类是2013+版本特性),修正变量名拼写错误,再添加扩展属性和过滤逻辑:

using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;

public void GetFocusedEmails()
{   
    // 必须使用Exchange2013及以上版本
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
    service.AutodiscoverUrl("example.user@contoso.com");     

    // 定义存储智能分类结果的扩展属性
    ExtendedPropertyDefinition inferenceClassificationProp = new ExtendedPropertyDefinition(
        DefaultExtendedPropertySet.Common,
        26338,
        MapiPropertyType.Integer);

    ItemView itemView = new ItemView(int.MaxValue, 0, OffsetBasePoint.Beginning);
    itemView.PropertySet = new PropertySet(BasePropertySet.IdOnly);
    itemView.PropertySet.RequestedBodyType = BodyType.Text;
    // 将分类属性加入请求集合,确保返回该字段
    itemView.PropertySet.Add(inferenceClassificationProp);

    // 创建过滤器:仅筛选Focused标签的邮件(值为0)
    SearchFilter focusedFilter = new SearchFilter.IsEqualTo(
        inferenceClassificationProp,
        0);

    // 传入过滤器执行搜索
    FindItemsResults<Item> findResults = service.FindItems(
        WellKnownFolderName.Inbox,
        focusedFilter,
        itemView);         

    // 遍历处理Focused邮件
    foreach (Item item in findResults.Items)
    {
        if (item is EmailMessage email)
        {
            // 此处添加邮件处理逻辑
        }
    }
}

关键说明

  • 扩展属性参数是Exchange标准定义的,不可修改:DefaultExtendedPropertySet.Common、ID26338、类型Integer。
  • 若要筛选Other标签邮件,只需将过滤器中的值改为1即可。

内容的提问来源于stack exchange,提问作者Baibakov

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 00:57:37