当前位置:编程学习 > 网站相关 >>

exchange2010 EWS 二次开发

我现在正在做 EWS二次开发,有段代码不能获取邮件类容和邮件附件,那位大侠指点一下。

/// <summary>
        /// 显示邮件
        /// </summary>
        /// <param name="address">获取邮件人地址</param>
        /// <returns></returns>
        #region GetNewMail
        public List<MessageType> GetNewMail(string address)
        {
            FindItemType findItemRequest = new FindItemType();
            findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
            
            ItemResponseShapeType itemProperties = new ItemResponseShapeType();
            itemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
            //============
            //BodyTypeResponseType btype = new BodyTypeResponseType();            
            //itemProperties.BodyType = btype;
            //============
            findItemRequest.ItemShape = itemProperties;            
            EmailAddressType box = new EmailAddressType();
            //box.MailboxType = MailboxTypeType.Mailbox;
            box.EmailAddress = address;

            DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
            folderIDArray[0] = new DistinguishedFolderIdType();
            folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;
            folderIDArray[0].Mailbox = box;
            
            findItemRequest.ParentFolderIds = folderIDArray;

            //查询条件
            RestrictionType restriction = GetMailRestrictionByUnRead();
           
            if (restriction != null)
                findItemRequest.Restriction = restriction;

            try
            {        
                
                FindItemResponseType findItemResponse = esb.FindItem(findItemRequest);
                
                ResponseMessageType[] rmta = findItemResponse.ResponseMessages.Items;
                
                return getMail(ref rmta);
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
        //获取邮件
        private List<MessageType> getMail(ref ResponseMessageType[] rmta)
        {
            List<MessageType> newMails = new List<MessageType>(30);
            if (rmta != null)
            {
                foreach (ResponseMessageType rmt in rmta)
                {
                    if (rmt is FindItemResponseMessageType)
                    {
                        FindItemResponseMessageType findItemResponse = (FindItemResponseMessageType)rmt;
                        if (findItemResponse.ResponseClass == ResponseClassType.Success)
                        {
                            if (findItemResponse.RootFolder.Item is ArrayOfRealItemsType)
                            {
                                
                                ;
                                ArrayOfRealItemsType obj = (ArrayOfRealItemsType)findItemResponse.RootFolder.Item;
                                //----                              
                                
                                //----
                                if (obj != null && obj.Items != null)
                                {
                                    foreach (ItemType item in obj.Items)
                                    {         
                                        
                                        if (item is MessageType)
                                        {
                                            MessageType message = (MessageType)item;                                            
                                            if (message != null)
                                            {
                                                newMails.Add(message);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return newMails;
        }


        private RestrictionType GetMailRestrictionByUnRead()
        {
            RestrictionType restriction = new RestrictionType();
            IsEqualToType isEqual = new IsEqualToType();
            
            FieldURIOrConstantType _fieldURIOrConstantType = new FieldURIOrConstantType();
            ConstantValueType _constant = new ConstantValueType();
            //控制读取邮件类型
            _constant.Value = "0";
            _fieldURIOrConstantType.Item = _constant;
            
            PathToUnindexedFieldType _pathToUnindexedFieldType = new PathToUnindexedFieldType();
            _pathToUnindexedFieldType.FieldURI = UnindexedFieldURIType.messageIsRead;
            
            isEqual.FieldURIOrConstant = _fieldURIOrConstantType;
            isEqual.Item = _pathToUnindexedFieldType;

            restriction.Item = isEqual;
            return restriction;
        }
        #endregion
--------------------编程问答-------------------- 通过 EMAILItemID 在读取一次
我的MSN:yang_chun2010@hotmail.com --------------------编程问答-------------------- 你是通过那种方式做二次开发的。
--------------------编程问答-------------------- 你好,请问exchange2010中的ExchangeServiceBinding这个类的dll你有吗?我这边引用了webservice,但是还是不行,能不能发给我一下,谢谢了!邮箱:caoqiancc@yahoo.com.cn
补充:企业软件 ,  Exchange Server
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,