EWS搜索过滤器以查找发件人域C#

时间:2017-01-27 12:10:30

标签: c# email exchangewebservices

我创建了一个小应用程序来获取我的所有电子邮件。我将每封电子邮件添加到列表中。然而,在我将它们添加到列表之前,我会过滤它们。我的所有过滤器都与一个过滤器不同。我的搜索过滤器用于过滤发件人的电子邮件不起作用,因为我只是尝试过滤域而不是整个电子邮件地址。例如xxx@xxx.com将过滤,但我想过滤掉xxx.com域的所有内容,并且由于某种原因它不会过滤它。我尝试使用子字符串,这也不起作用。

我的代码是休闲

    private static SearchFilter.SearchFilterCollection sFilter = new SearchFilter.SearchFilterCollection();
     private static FindItemsResults<Item> findResults;
        sFilter.Add(new SearchFilter.Not(new SearchFilter.ContainsSubstring(EmailMessageSchema.Sender, "@xxx.com",ContainmentMode.Substring,ComparisonMode.IgnoreCase)));
        sFilter.Add(new SearchFilter.Not(new SearchFilter.Exists(EmailMessageSchema.InReplyTo)));
        DateTime startTime = GetDateValueforFilter();
        startTimefilter = new SearchFilter.IsGreaterThanOrEqualTo(EmailMessageSchema.DateTimeReceived, startTime);
sFilter.Add(startTimefilter);


            sFilter.Add(startTimefilter);


            findResults = service.FindItems(
                WellKnownFolderName.Inbox
                ,sFilter
                ,new ItemView(25));

            foreach (EmailMessage item in findResults.Items)
            {



                //if (item.IsRead == false)
                //{
                //    if (item.InReplyTo == null)
                //    {


                        bool replyToAll = true;
                        string myReply = "This is the message body of the email reply.";

                        item.Reply(myReply, replyToAll);

                        item.IsRead = true;
                        item.Send();


                    //}

                //}

            }

1 个答案:

答案 0 :(得分:0)

我建议您尝试使用扩展属性PidTagSenderSmtpAddress https://msdn.microsoft.com/en-us/library/office/jj713594.aspx并尝试类似

  ExtendedPropertyDefinition PidTagSenderSmtpAddress = new ExtendedPropertyDefinition(0x5D01,MapiPropertyType.String);
  SearchFilter sf = new SearchFilter.ContainsSubstring(PidTagSenderSmtpAddress, "@yahoo.com");