本文介绍了使用Exchange Web服务获取特定日期的邮件在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够从基于一个主题的邮箱中取邮件。我不知道什么获取基于接收日期电子邮件的格式

 字符串消息=的String.Empty?; 
项目项目= Item.Bind(exService,MESSAGEID,PropertySet.FirstClassProperties);

如果(产品EmailMessage)
{
EmailMessage EM =(EmailMessage)项目;

字符串strMsg =的String.Empty;
// strMsg = strMsg + item.Id.ToString();
// strMsg = strMsg + item.DateTimeReceived;
strMsg = strMsg + + item.DateTimeReceived +***********************上收到的新财政通过电子邮件将****** ******************************+ Environment.NewLine;

如果(em.Body.Text.Contains(布兰登))
{
strMsg = strMsg + em.Body.Text.ToString();
}
strMsg = strMsg +***********************电子邮件正文结束********* ***************************+ Environment.NewLine;
=消息strMsg;

}


解决方案

我觉得SilverNinja告诉你的方法是正确的方式。
你应该寻找这样的项目:

 的DateTime searchdate =新日期时间(2012,7,6)//年,月,日
SearchFilter greaterthanfilter =新SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived,searchdate);
SearchFilter lessthanfilter =新SearchFilter.IsLessThan(ItemSchema.DateTimeReceived,searchdate.AddDays(1));
SearchFilter过滤器=新SearchFilter.SearchFilterCollection(LogicalOperator.And,greaterthanfilter,lessthanfilter);
文件夹文件夹= Folder.Bind(this.m_Service,WellKnownFolderName.MsgFolderRoot); //或者你想在
FindItemsResults<搜索的文件夹;项目>结果= folder.FindItems(过滤器,新的ItemView控件(1000));



results.Items将返回第一个1000个项目这是你正在寻找的一天recivied


I am able to fetch emails from a mailbox based on a subject. I am not sure what the format for fetching emails based on the received date?

           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;

            }
解决方案

I think the way SilverNinja told you is the right way.You should search the items like this:

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" will return the first 1000 items which are recivied at the day you are looking for.

这篇关于使用Exchange Web服务获取特定日期的邮件在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 20:46