7

我能够根据主题从邮箱中获取电子邮件。我不确定根据接收日期获取电子邮件的格式是什么?

           string message = string.Empty;
            Item item = Item.Bind(exService, messageID, PropertySet.FirstClassProperties);

            if (item is EmailMessage)
            {
                EmailMessage em = (EmailMessage)item;

                string strMsg = string.Empty;
                //strMsg = strMsg + item.Id.ToString();
                //strMsg = strMsg + item.DateTimeReceived;
                strMsg = strMsg + "*********************** New Fiscal Email received on " + item.DateTimeReceived  +" ************************************" + Environment.NewLine;

                if (em.Body.Text.Contains("BRANDON"))
                {
                    strMsg = strMsg + em.Body.Text.ToString();
                }
                strMsg = strMsg + "*********************** End of Email Body ************************************" + Environment.NewLine;
                message = strMsg;

            }
4

3 回答 3

20

我认为 SilverNinja 告诉你的方式是正确的方式。您应该像这样搜索项目:

DateTime searchdate = new DateTime (2012,7,6) //Year, month, day
SearchFilter greaterthanfilter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, searchdate );
SearchFilter lessthanfilter = new SearchFilter.IsLessThan(ItemSchema.DateTimeReceived, searchdate.AddDays(1));
SearchFilter filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, greaterthanfilter, lessthanfilter);
Folder folder = Folder.Bind(this.m_Service, WellKnownFolderName.MsgFolderRoot); //Or the folder you want to search in
FindItemsResults<Item> results = folder.FindItems(filter, new ItemView(1000));

“results.Items”将返回您正在寻找的当天收到的前 1000 个项目。

于 2012-07-06T13:31:34.857 回答
3

看看SearchFilter例子。你只需要一个过滤条件ItemSchema.DateTimeReceived

于 2012-06-11T16:28:48.830 回答
-2

这将起作用。

if (em.DateTimeReceived.Equals(**Date you want to search**))
                {
                    strMsg = strMsg + em.Body.Text.ToString();
                }
于 2012-06-20T05:26:14.207 回答