上一篇介绍的Exchange2007客户端程序中怎么发送邮件。
现在,我来简单介绍一下怎么收取邮件。
来看代码:

   public Hashtable GetAllMails(DateTime StartDate, DateTime EndDate)
        {
            try
            {
                if (null == this.m_esb) return null;

                DistinguishedFolderIdType[] dfit = new DistinguishedFolderIdType[1];

                //get the root folder ID

                dfit[0] = new DistinguishedFolderIdType();

                dfit[0].Id = DistinguishedFolderIdNameType.inbox;

                //set the props that we want to retrieve

                FolderResponseShapeType frst = new FolderResponseShapeType();

                frst.BaseShape = DefaultShapeNamesType.AllProperties;

                //get the folder

                GetFolderType gftRoot = new GetFolderType();

                gftRoot.FolderIds = dfit;

                gftRoot.FolderShape = frst;

                GetFolderResponseType gfrt = this.m_esb.GetFolder(gftRoot);

                FolderInfoResponseMessageType firmt = ((FolderInfoResponseMessageType)gfrt.ResponseMessages.Items[0]);

                   
                FolderIdType[] fita = new FolderIdType[1];

                fita[0] = new FolderIdType();

                if (firmt.ResponseClass == ResponseClassType.Success)
                {
                    fita[0].Id = ((FolderInfoResponseMessageType)gfrt.ResponseMessages.Items[0]).Folders[0].FolderId.Id;
                }

                if (fita[0].Id == null) return new Hashtable();
                //request AllProperties

                PathToUnindexedFieldType[] ptufta = new PathToUnindexedFieldType[1];

                ptufta[0] = new PathToUnindexedFieldType();

                ptufta[0].FieldURI = UnindexedFieldURIType.itemItemClass;

                ItemResponseShapeType irst = new ItemResponseShapeType();

                irst.BaseShape = DefaultShapeNamesType.AllProperties;

                irst.IncludeMimeContent = false;

                irst.AdditionalProperties = ptufta;

                //restrict the returned items to just items of a specific message class

                PathToUnindexedFieldType MsgClassField = new

                PathToUnindexedFieldType();

                MsgClassField.FieldURI = UnindexedFieldURIType.itemItemClass;

                ConstantValueType MsgClassToGet = new ConstantValueType();

                MsgClassToGet.Value = "IPM.NOTE";

                FieldURIOrConstantType MsgClassConstant = new FieldURIOrConstantType();

                MsgClassConstant.Item = MsgClassToGet;

                IsEqualToType iett = new IsEqualToType();

                iett.FieldURIOrConstant = MsgClassConstant;

                iett.Item = MsgClassField;

                //restrict the returned items greater than a specified date

                PathToUnindexedFieldType StartDateReceivedField = new PathToUnindexedFieldType();

                StartDateReceivedField.FieldURI = UnindexedFieldURIType.itemDateTimeReceived;

                ConstantValueType StartDateReceivedToGet = new ConstantValueType();

                StartDateReceivedToGet.Value = StartDate.ToUniversalTime().ToString();

                FieldURIOrConstantType StartDateReceivedConstant = new FieldURIOrConstantType();

                StartDateReceivedConstant.Item = StartDateReceivedToGet;

                IsGreaterThanOrEqualToType igtett = new IsGreaterThanOrEqualToType();

                igtett.FieldURIOrConstant = StartDateReceivedConstant;

                igtett.Item = StartDateReceivedField;


                //restrict the returned items less than a specified date

                PathToUnindexedFieldType EndDateReceivedField = new PathToUnindexedFieldType();

                EndDateReceivedField.FieldURI = UnindexedFieldURIType.itemDateTimeReceived;

                ConstantValueType EndDateReceivedToGet = new ConstantValueType();

                EndDateReceivedToGet.Value = EndDate.ToUniversalTime().ToString();

                FieldURIOrConstantType EndDateReceivedConstant = new FieldURIOrConstantType();

                EndDateReceivedConstant.Item = EndDateReceivedToGet;

                IsLessThanOrEqualToType iltett = new IsLessThanOrEqualToType();

                iltett.FieldURIOrConstant = EndDateReceivedConstant;

                iltett.Item = EndDateReceivedField;

                AndType at = new AndType();

                at.Items = new SearchExpressionType[3];

                at.Items[0] = igtett;

                at.Items[1] = iltett;

                at.Items[2] = iett;

                //TODO: Uncomment the following line if you want to display only email items from folder

                // If the following line is commented then all items would be returned from folder, 

                // for e.g. Reports, Appointment, Meeting Requests, Contacts etc.


                RestrictionType rt = new RestrictionType();

                rt.Item = at;

                //find the items

                FindItemType fit = new FindItemType();

                fit.ItemShape = irst;

                fit.ParentFolderIds = fita;

                fit.Restriction = rt;

                FindItemResponseType firt = m_esb.FindItem(fit);

                // That's it!  
                ItemType[] list = ((ArrayOfRealItemsType)((FindItemResponseMessageType)firt.ResponseMessages.Items[0]).RootFolder.Item).Items;  // Emails We want to.

                //foreach (ItemType i in list)
                //{
                //    SetIsReadFlag(i.ItemId);//set is read flag.
                //}

                Hashtable ht = new Hashtable();
 
                if (list != null)
                {
                    foreach (ItemType itemOne in list)
                    {
                        ItemType Item = new ItemType();
                        ht.Add(Item.ItemId, Item);
                    }
                }
                return ht;
            }
            catch (Exception e)
            {
                throw new Exception("Error :" + e.Message);
            }
        }

那么得到的Hashtable 则是目标邮件的队列:)

转载于:https://www.cnblogs.com/davidwangxl/archive/2008/06/16/1223329.html

Exchage 2007 Client Application Functions(2) -- 如何收取邮件相关推荐

  1. Twitter登录Callback URL not approved for this client application错误记录

    因为做的APP是面向海外版,这两天突然说Twitter登录失败,查了各种原因和解决方案,最终解决,并提供两种解决方案. Twitter大佬更新授权认证机制,应用后台没有更新过来,导致大面积登录出问题, ...

  2. Excel 2007 (Excel.Application) Workbooks.Add 出现内存不够的解决办法

    Workbooks.Add时,会出现以下错误: Microsoft Office Excel 错误 '800a03ec' 内存或磁盘空间不足,Microsoft Office Excel 无法再次打开 ...

  3. 让Exchange 2010 (2007适用)可以收发外部邮件

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://cnbeta.blog.51cto.com/1234897/276803 上一篇教 ...

  4. 日记 [2007年02月03日]邮件退信问题的解决

    经过多日的调整终于将公司使用的邮件服务器加载附件后的退信问题在今天解决了,实在太高兴了. 虽然经过了3日的纷争,终于在今天有了结果,在这期间真的一段时间几乎想放弃修改,从外面选择使用其他人提供的企业邮 ...

  5. How to: Build a Client Application

    转载于:http://msdn.microsoft.com/en-us/library/y6dc64f2(v=vs.80).aspx 转载于:https://www.cnblogs.com/aran/ ...

  6. Exchange 2007 术语表

    此术语表帮助解释与 Microsoft Exchange Server 2007 关联的核心概念和技术. 术语和定义:术语定义 接受域 (accepted domain)Exchange 组织为其发送 ...

  7. 创建基于MailKit和MimeKit的.NET基础邮件服务

    邮件服务是一般的系统都会拥有和需要的功能,但是对于.NET项目来说,邮件服务的创建和使用会较为的麻烦..NET对于邮件功能提供了System.Net.Mail用于创建邮件服务,该基础服务提供邮件的基础 ...

  8. 用C#实现用免费smtp服务器(GMail)发邮件(转)

    原文地址:http://www.cnblogs.com/skywind/archive/2007/09/21/901734.html Method 1 ------------------------ ...

  9. 邮件服务器(eas)找不到服务器,Exchange ActiveSync 无法访问邮箱服务器上的邮箱,因为邮箱服务器处于脱机状态...

    上一次修改主题: 2015-03-08 Microsoft Operations Manager 的 Microsoft Exchange Server 2007 管理包可以监视运行 Exchange ...

最新文章

  1. 日期相减计算年_Excel教程:excel日期问题的小妙招
  2. 坑!自己走过的坑...
  3. NPOI 将DataGridView导出到Excel
  4. 十六进制报文用wireshark打开
  5. 学习计划(11.5)
  6. ASP.NET:关于.net中的runat
  7. fis 前端构建工具
  8. 数据结构(C语言)-串
  9. Eclipse汉化教程
  10. 城市规划CAD影像底图快速导入方法
  11. gitlab内网部署clone push速度快,网页反应慢
  12. .html页面缓存问题
  13. 计算机网络管理工程师技术水平证书,计算机网络管理工程师技术水平证书有什么用...
  14. 2012年8月传统编程语言就业趋势分析(图)
  15. matlab 图像处理之Refined Lee滤波
  16. 模拟QQ自动隐藏窗体
  17. 基于scrapy-redis的分布式腾讯新闻爬虫
  18. Openssl移植到ARM开发板
  19. 美国虚拟PSTN号码
  20. WK2124下linux驱动分析与移植

热门文章

  1. CUDA Samples: Image Process: BGR to BGR565
  2. 有效的rtsp流媒体测试地址汇总
  3. 【Qt】错误处理:error: undefined reference to `qMain(int, char**)‘
  4. 澳洲计算机学,2020年澳洲计算机科学专业工作好找吗
  5. linux db2 修改日志路径,db2中更改日志文件大小及其个数
  6. html手机不能自动播放音乐,解决移动端浏览器 HTML 音频不能自动播放的三种方法...
  7. 计算机语言编程能力有哪些,除了编程语言,程序员还需要具备哪些能力
  8. 使用Maven 打包项目 生成XXX.tar.gz 文件
  9. 小程序将form表单数据写入云数据库
  10. python queue 多进程_python中的Queue与多进程(multiprocessing)