【问题标题】:EWS search filter to find sender domain C#EWS 搜索过滤器以查找发件人域 C#
【发布时间】:2017-01-30 06:37:06
【问题描述】:

我创建了一个小型应用程序来接收我的所有电子邮件。我将每封电子邮件添加到列表中。但是,在将它们添加到列表之前,我会过滤它们。我所有的过滤器都在除一个之外工作。我用于按发件人过滤我的电子邮件的搜索过滤器不起作用,因为我只是试图过滤域而不是整个电子邮件地址。例如 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();


                    //}

                //}

            }

【问题讨论】:

标签: c# email exchangewebservices


【解决方案1】:

我建议您尝试使用扩展属性 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");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-12
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多