示例#1
0
        /// <summary>
        /// Asks Exchange to send a specific message.
        /// </summary>
        /// <param name="messageId"></param>
        public void SendMessage(ItemIdType messageId)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            // Send message
            var sendItem = new SendItemType { ItemIds = new BaseItemIdType[1], SavedItemFolderId = new TargetFolderIdType() };
            var siSentItemsFolder = new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.sentitems };

            sendItem.SavedItemFolderId.Item = siSentItemsFolder;
            sendItem.SaveItemToFolder = true;
            sendItem.ItemIds[0] = messageId;

            SendItemResponseType sendItemResponse = binding.SendItem(sendItem);

            if (sendItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                throw new Exception(sendItemResponse.ResponseMessages.Items[0].MessageText);
        }
示例#2
0
        /// <summary>
        /// Gets the nr of items in a given folder
        /// </summary>
        /// <returns></returns>
        public long GetNrItemsInFolder(ChannelFolder folder)
        {
            var binding = ChannelHelper.BuildChannel(hostname, username, password);

            var findItemRequest = new FindItemType { Traversal = ItemQueryTraversalType.Shallow };
            var itemProperties = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.AllProperties };
            findItemRequest.ItemShape = itemProperties;

            var folderIdArray = new DistinguishedFolderIdType[2];
            folderIdArray[0] = new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.inbox };

            findItemRequest.ParentFolderIds = folderIdArray;

            FindItemResponseType findItemResponse = binding.FindItem(findItemRequest);

            // Determine whether the request was a success.
            if (findItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
                throw new Exception(findItemResponse.ResponseMessages.Items[0].MessageText);

            var responseMessage =
                (FindItemResponseMessageType) findItemResponse.ResponseMessages.Items[0];

            var mailboxItems = (ArrayOfRealItemsType)responseMessage.RootFolder.Item;

            if (mailboxItems.Items == null) return 0;

            return mailboxItems.Items.Length;
        }