【问题标题】:searching Exchange mailbox by email address using SearchFilterCollection使用 SearchFilterCollection 按电子邮件地址搜索 Exchange 邮箱
【发布时间】:2014-04-10 15:00:51
【问题描述】:

我正在使用 Exchange Web 服务搜索电子邮件收件箱(在 Exchange 2010 上)。

在我的 SearchFilterCollection 中,我想包含电子邮件的 From.Address 属性,因为我只想检索包含特定域(例如 @domain.co.uk)的电子邮件

这是我的代码:

SearchFilter.SearchFilterCollection searchFilterCollection = new SearchFilter.SearchFilterCollection(LogicalOperator.And);
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
searchFilterCollection.Add(new SearchFilter.IsEqualTo(EmailMessageSchema.HasAttachments, true));

// **** PROBLEM HERE ON BELOW LINE****       
searchFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, "@domain.co.uk")); // 

// add the exceptions
for (int iEx = 0; iEx < e2c.emailExceptions.Count; iEx++)
    {
    searchFilterCollection.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, e2c.emailExceptions[iEx])));
    }

    ItemView view = new ItemView(100);
    view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Ascending);

    // Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
    FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, searchFilterCollection, view);

有没有在 SearchFilter 中包含电子邮件地址的好方法?

【问题讨论】:

    标签: exchangewebservices exchange-server-2010 searchfiltercollection


    【解决方案1】:

    前几天我刚刚创建了一个搜索文件夹,使用来自How to: Work with search folders by using EWS in Exchange 主题的示例:

    // Create a search filter to express the criteria
    // for the folder.
    EmailAddress manager = new EmailAddress("sadie@contoso.com");
    
    SearchFilter.IsEqualTo fromManagerFilter =
        new SearchFilter.IsEqualTo(EmailMessageSchema.Sender, manager);
    

    现在这是使用 Sender 属性,而不是 From 属性。我认为您可以简单地将一个替换为另一个,但我没有测试确定。

    【讨论】:

    • 你认为有可能做类似的事情:SearchFilter.ContainsSubstring fromManagerFilter = new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, "@bankofcyprus.co.uk"); 吗?
    • 我认为这会奏效,但是当我认为我应该得到结果时,我只是尝试并没有得到任何结果。但我没有收到错误。这个周末我可以多看看我的代码——现在不行。
    • 因此,我没有使用 ContainsSubstring 搜索过滤器获得预期结果。然而,当我使用以下 ASQ 搜索时,我确实得到了预期的结果:string queryString = "from:\"domain.co.uk\"";FindItemsResults&lt;Item&gt; results = service.FindItems (WellKnownFolderName.Inbox, queryString, view);
    • 感谢 Mimi,看来唯一的选择是用动态创建的 AQS 查询字符串替换我的 EWS SearchFilter 集合...
    • 关于这个问题的任何想法:EWS retrieve mail item attachment error
    猜你喜欢
    • 2012-11-26
    • 2020-12-04
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多