none
how can i programatically retrieve sender email address from inbox mail items through exchange web service proxy via C# RRS feed

  • Question

  • Help me programatically through C# to get Sender Email Address from exchange web service proxy. Is there any way to cast object of type ItemType or MessageType into EmailAddressType.

    Itemtype myMessageItem=new ItemType();

    MessageType myMessageType=new MessageType();

    myMessageType=(MesageType)myMessageItem;

    During debugging mode i am able to view the sender email address in the debugger window box but i am unable to fetch the email address from the ItemType or MessageType object but the SenderEmailAddress property is available in EmailAddressType.Is there anyway to cast or any other way to access it. 



    judo

    Sunday, February 12, 2012 1:22 PM

Answers

  • Sorry I can't really read what you posted if you going to post code make sure you use the Insert code Button which is on the format bar.

    If your trying to use a GetItem request it should look something like

    DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.inbox;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
                
                PathToExtendedFieldType PidTagSenderSmtpAddress = new PathToExtendedFieldType();
                PidTagSenderSmtpAddress.PropertyTag = "0x5D01";
                PidTagSenderSmtpAddress.PropertyType = MapiPropertyTypeType.String;
    
                ipItemProperties.AdditionalProperties = new BasePathToElementType[1];
                ipItemProperties.AdditionalProperties[0] = PidTagSenderSmtpAddress;
    
                IndexedPageViewType ipvt = new IndexedPageViewType();
                ipvt.BasePoint = IndexBasePointType.Beginning;
                ipvt.MaxEntriesReturned = 10;
                ipvt.MaxEntriesReturnedSpecified = true;
                ipvt.Offset = 0;
    
                fiFindItemRequest.Item = ipvt;
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray; 
    
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (MessageType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                GetItemType giType = new GetItemType();
                                giType.ItemIds = new BaseItemIdType[1];
                                giType.ItemIds[0] = miMailboxItem.ItemId;
                                giType.ItemShape = new ItemResponseShapeType();
                                giType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
                                GetItemResponseType getItemResponse = esb.GetItem(giType);
                                ItemInfoResponseMessageType getItemResponseMessage =
                                    getItemResponse.ResponseMessages.Items[0]
                                    as ItemInfoResponseMessageType;
    
                                if (getItemResponseMessage != null)
                                {
                                    if (getItemResponseMessage.ResponseClass ==
                                        ResponseClassType.Success)
                                    {
                                        MessageType Message = (MessageType)getItemResponseMessage.Items.Items[0];
                                        Console.WriteLine(Message.Sender.Item.EmailAddress);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }
    

    Cheers
    Glen

    • Marked as answer by jegan1810 Friday, February 17, 2012 11:46 AM
    Wednesday, February 15, 2012 9:15 AM

All replies

  • By default the Senders email address isn't returned in a FindItems operation (only the displayname is which may or may not contain to the email address depending on how it was sent). So to get the SenderAddress normaly you would need to do a GetItem Request which will return the Sender Address populated. Otherwise if you use the PidTagSenderSmtpAddress Extended Property that should also work without the extra GetItem eg

                DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.inbox;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
                
                PathToExtendedFieldType PidTagSenderSmtpAddress = new PathToExtendedFieldType();
                PidTagSenderSmtpAddress.PropertyTag = "0x5D01";
                PidTagSenderSmtpAddress.PropertyType = MapiPropertyTypeType.String;
    
                ipItemProperties.AdditionalProperties = new BasePathToElementType[1];
                ipItemProperties.AdditionalProperties[0] = PidTagSenderSmtpAddress;
    
                IndexedPageViewType ipvt = new IndexedPageViewType();
                ipvt.BasePoint = IndexBasePointType.Beginning;
                ipvt.MaxEntriesReturned = 10;
                ipvt.MaxEntriesReturnedSpecified = true;
                ipvt.Offset = 0;
    
                fiFindItemRequest.Item = ipvt;
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray; 
    
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (MessageType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                Console.Write(miMailboxItem.ExtendedProperty[0].Item);
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }

    To make life easier instead of using Proxy code you might want to look at the EWS Managed API which will save you many hours of work.

    cheers
    Glen

    Tuesday, February 14, 2012 4:34 AM
  • review the code below as i have problem fetching "email address" from sender 
    
    and while i try with my code error i get is "Object refernce not set to an instance of the object" 
    
    i am able to fetch messages[j].Subject,messages[j].DateTimeSent,messages[j].Body.value 
    
    but only EmailAddress is found deep inside object messages[j] debugger window 
    
    namespace HCLTEWS 
    
    { public partial class test2 : Form { public test2() { InitializeComponent(); }
    
     private void BtnLogin_Click(object sender, EventArgs e) 
    
    { ExchangeServiceBinding esb = new ExchangeServiceBinding(); 
    
    esb.Credentials = new NetworkCredential("uername", "password", "hcltech"); 
    
    esb.Url = @"https://hcltmail-chn.hcl.in/EWS/exchange.asmx"; 
    
    try {
    
     FindItemType findItemRequest = new FindItemType();
    
     findItemRequest.Traversal = ItemQueryTraversalType.Shallow; //------------------------------->1
    
     // define which item properties are returned in the response 
    
    ItemResponseShapeType itemProperties = new ItemResponseShapeType(); 
    
    itemProperties.BaseShape = DefaultShapeNamesType.AllProperties; 
    
    findItemRequest.ItemShape = itemProperties;//------------------------------------------------>2 // 
    
    identify which folder to search 
    
    DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1]; 
    
    folderIDArray[0] = new DistinguishedFolderIdType(); 
    
    folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;
    
     // add folders to request findItemRequest.ParentFolderIds = folderIDArray;//------------------------------------------->3
    
     // find the messages FindItemResponseType findItemResponse = esb.FindItem(findItemRequest); 
    
    // read returned 
    
    FindItemResponseMessageType folder = (FindItemResponseMessageType)findItemResponse.ResponseMessages.Items[0]; ArrayOfRealItemsType folderContents = new ArrayOfRealItemsType(); 
    
    folderContents = (ArrayOfRealItemsType)folder.RootFolder.Item; 
    
    ItemType[] items = folderContents.Items; 
    
    // if no messages were found, then return null -- we're done 
    if (items == null || items.Count() <= 0) 
    MessageBox.Show("no mails inside"); 
    else 
    { 
    // FindItem never gets "all" the properties, so now that we've found them all, we need to get them all. BaseItemIdType[] itemIds = new BaseItemIdType[items.Count()]; 
    for (int i = 0; i < items.Count(); i++) 
    { 
    itemIds[i] = items[i].ItemId; 
    } 
    GetItemType getItemType = new GetItemType(); getItemType.ItemIds = itemIds; 
    getItemType.ItemShape = new ItemResponseShapeType(); getItemType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; getItemType.ItemShape.BodyType = BodyTypeResponseType.Text; getItemType.ItemShape.IncludeMimeContentSpecified = true; getItemType.ItemShape.IncludeMimeContent = true; getItemType.ItemShape.BodyTypeSpecified = true; 
    
    //getItemType.ItemShape.AdditionalProperties getItemResponse = esb.GetItem(getItemType); ItemType[] messages = new ItemType[getItemResponse.ResponseMessages.Items.Count()]; ResponseObjectType[] responseobjectType = new ResponseObjectType[items.Count()]; 
    EmailAddressType[] emailAddressTypeObj=new EmailAddressType[items.Count()] ; 
    SingleRecipientType[] singleRecipientFromObj=new SingleRecipientType[items.Count()] ; 
    ReplyToItemType[] replytoitemType = new ReplyToItemType[items.Count()]; 
    MessageType[] messTypeObj=new MessageType[items.Count()]; 
    for (int j = 0; j < messages.Count(); j++) 
    { 
    messages[j] = ((ItemInfoResponseMessageType)getItemResponse.ResponseMessages.Items[j]).Items.Items[0];-------->in Debugger window i am to see sender EmailAddress value deep inside messages[j]. 
    //------------------No problem down the 4 lines as they direct to fetch under messages[j]----------------------------------- 
    MessageBox.Show("message Subject :" + messages[j].Subject); 
    MessageBox.Show("message Body : " + messages[j].Body.Value); 
    MessageBox.Show("DateTime Sent :" + messages[j].DateTimeSent); 
    MessageBox.Show("Display To : " + messages[j].DisplayTo); 
    //-----------------------------------------------------------------------------------------------
    
    //-------------------All of My code tried below Produces error "Object Ref nt set to instance of an object"-------------- 
    
    
    emailAddressTypeObj[j].EmailAddress = message[j].ResponseObjects[0].Sender.Item.EmailAddress; 
    
    //emailAddressTypeObj[j].EmailAddress = ((((ItemInfoResponseMessageType)getItemResponse.ResponseMessages.Items[j]).Items.Items[0]).ResponseObjects[0].Sender.Item.EmailAddress); 
    
    //MessageBox.Show("EmailAddress: "+messages[j].ResponseObjects[0].From.Item.EmailAddress);
    
    //MessageBox.Show("email address :" + emailAddressTypeObj[j].EmailAddress); 
    
    MessageBox.Show("eMAIL ADDRESS :" + ((((ItemInfoResponseMessageType)getItemResponse.ResponseMessages.Items[j]).Items.Items[0]).ResponseObjects[0]).From.Item.EmailAddress);--->when i try with i get "Object refernce not set to an instance of the object" 
    
    //======================================================================================================= 
    //MessageBox.Show("Conversation Index :" + messTypeObj[j].ConversationIndex.ToString()); 
    //MessageBox.Show("Conversation Topic :" + messTypeObj[j].ConversationTopic); 
    } 
    } 
    } 
    catch (Exception ex1) 
    { 
    MessageBox.Show("message :" + ex1.Message + "\n\nsource : " + ex1.Source + "\n\ntrace : " + ex1.StackTrace); 
    } 
    finally 
    { } 
    } 
    } 
    } 

    • Edited by jegan1810 Wednesday, February 15, 2012 11:54 AM Please now review my code which would be clear now
    Wednesday, February 15, 2012 7:13 AM
  • Sorry I can't really read what you posted if you going to post code make sure you use the Insert code Button which is on the format bar.

    If your trying to use a GetItem request it should look something like

    DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.inbox;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
                
                PathToExtendedFieldType PidTagSenderSmtpAddress = new PathToExtendedFieldType();
                PidTagSenderSmtpAddress.PropertyTag = "0x5D01";
                PidTagSenderSmtpAddress.PropertyType = MapiPropertyTypeType.String;
    
                ipItemProperties.AdditionalProperties = new BasePathToElementType[1];
                ipItemProperties.AdditionalProperties[0] = PidTagSenderSmtpAddress;
    
                IndexedPageViewType ipvt = new IndexedPageViewType();
                ipvt.BasePoint = IndexBasePointType.Beginning;
                ipvt.MaxEntriesReturned = 10;
                ipvt.MaxEntriesReturnedSpecified = true;
                ipvt.Offset = 0;
    
                fiFindItemRequest.Item = ipvt;
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray; 
    
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (MessageType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                GetItemType giType = new GetItemType();
                                giType.ItemIds = new BaseItemIdType[1];
                                giType.ItemIds[0] = miMailboxItem.ItemId;
                                giType.ItemShape = new ItemResponseShapeType();
                                giType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
                                GetItemResponseType getItemResponse = esb.GetItem(giType);
                                ItemInfoResponseMessageType getItemResponseMessage =
                                    getItemResponse.ResponseMessages.Items[0]
                                    as ItemInfoResponseMessageType;
    
                                if (getItemResponseMessage != null)
                                {
                                    if (getItemResponseMessage.ResponseClass ==
                                        ResponseClassType.Success)
                                    {
                                        MessageType Message = (MessageType)getItemResponseMessage.Items.Items[0];
                                        Console.WriteLine(Message.Sender.Item.EmailAddress);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }
    

    Cheers
    Glen

    • Marked as answer by jegan1810 Friday, February 17, 2012 11:46 AM
    Wednesday, February 15, 2012 9:15 AM
  • it would be a lot helpful if u could provide the additional code to retrieve ConversationalId, and ConversationalIndex


    judo

    Wednesday, February 22, 2012 9:24 AM
  • What version of Exchange are you using If you using 2010 as long as you set the RequestedServerVersion to 2010 eg

                esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;

    you should be able to do

                                        MessageType Message = (MessageType)getItemResponseMessage.Items.Items[0];
                                        Console.WriteLine(Message.ConversationId);
                                        Console.WriteLine(Message.ConversationIndex);
                                        Console.WriteLine(Message.Sender.Item.EmailAddress);

    On 2007 you would need to define the Mapi property and use the Additional properties.

    Cheers
    Glen

    Thursday, February 23, 2012 3:54 AM
  • ya we are using Exchange2007_SP1
    esb.RequestServerVersionValue = new RequestServerVersion();
                esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;

    help me out with how  to define the Mapi property and use the Additional properties.

    judo

    Thursday, February 23, 2012 5:27 AM
  • Try something like

               DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.inbox;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
                
                PathToExtendedFieldType PidTagSenderSmtpAddress = new PathToExtendedFieldType();
                PidTagSenderSmtpAddress.PropertyTag = "0x5D01";
                PidTagSenderSmtpAddress.PropertyType = MapiPropertyTypeType.String;
    
                PathToExtendedFieldType PidTagConversationIndex = new PathToExtendedFieldType();
                PidTagConversationIndex.PropertyTag = "0x0071";
                PidTagConversationIndex.PropertyType = MapiPropertyTypeType.Binary;
    
                PathToExtendedFieldType PidTagConversationId = new PathToExtendedFieldType();
                PidTagConversationId.PropertyTag = "0x3013";
                PidTagConversationId.PropertyType = MapiPropertyTypeType.Binary;
    
                ipItemProperties.AdditionalProperties = new BasePathToElementType[3];
                ipItemProperties.AdditionalProperties[0] = PidTagSenderSmtpAddress;
    
    
                IndexedPageViewType ipvt = new IndexedPageViewType();
                ipvt.BasePoint = IndexBasePointType.Beginning;
                ipvt.MaxEntriesReturned = 10;
                ipvt.MaxEntriesReturnedSpecified = true;
                ipvt.Offset = 0;
    
                fiFindItemRequest.Item = ipvt;
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray; 
    
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (MessageType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                GetItemType giType = new GetItemType();
                                giType.ItemIds = new BaseItemIdType[1];
                                giType.ItemIds[0] = miMailboxItem.ItemId;
                                giType.ItemShape = new ItemResponseShapeType();
                                giType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
                                giType.ItemShape.AdditionalProperties = new BasePathToElementType[2];
                                giType.ItemShape.AdditionalProperties[0] = PidTagConversationId;
                                giType.ItemShape.AdditionalProperties[1] = PidTagConversationIndex;
                                
                                GetItemResponseType getItemResponse = esb.GetItem(giType);
                                ItemInfoResponseMessageType getItemResponseMessage =
                                    getItemResponse.ResponseMessages.Items[0]
                                    as ItemInfoResponseMessageType;
    
                                if (getItemResponseMessage != null)
                                {
                                    if (getItemResponseMessage.ResponseClass ==
                                        ResponseClassType.Success)
                                    {
                                        MessageType Message = (MessageType)getItemResponseMessage.Items.Items[0];
                                        Console.WriteLine(Message.ExtendedProperty[0].Item);
                                        Console.WriteLine(Message.ExtendedProperty[1].Item);
                                        Console.WriteLine(Message.Sender.Item.EmailAddress);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }
    Cheers
    Glen
    Thursday, February 23, 2012 5:40 AM
  • Console.WriteLine(Message.ExtendedProperty[1].Item);

    At this line i receive error as "Index was out of bounds"

    judo

    Thursday, February 23, 2012 5:59 AM
  • Okay well looking at a Exchange 2007 mailbox the PidTagConversationId isnt set by the store which is why its not being returned you can have a a read of http://msdn.microsoft.com/en-us/library/ee204279%28v=exchg.80%29.aspx which tells you how you can calculate it based on other properties. (What are you trying to use it for anyway on 2007?)

    Cheers
    Glen

    Just to add to that in the document it states

    <1> Section 2.2.1.2: The computation of the value of the PidTagConversationId property is not supported by Exchange 2003, Exchange 2007, Office Outlook 2003, and Office Outlook 2007.

    Thursday, February 23, 2012 6:09 AM
  • i tried Glen to use Guid

     Console.WriteLine("Conversation ID " + Guid.Parse(Message.ExtendedProperty[1].Item.ToString()));

    is the above syntax correct and also how to set the PidTagConversationIndexTracking property to TRUE inorder tocalculate ConversationId as for using Exchange2007_SP1 as i am in need of using the ConversationId. Also during Debuging i am to view the 22 byte long ConversationIndex but could not display it using Console.WriteLine(Message.ExtendedProperty[1].Item);   help me to use Guid .

    judo

    Thursday, February 23, 2012 11:12 AM
  • No its not as I said and that doucmentation pointed "The computation of the value of the PidTagConversationId property is not supported" on Exchange 2007. So why do you need it what are you trying to achieve ? I would suggest you look at the Items Mapi properties with a Mapi editor like OutlookSpy of MFCMapi this will tell you what you can and can't retreive on a Item using EWS.

    With that sample because the PidTagConversationId  isn't set on 2007 it won't be returned so the only thing in the ExtendedProperty collection would be the PidTagConversationIndex so on 2007 this would be valid

                DistinguishedFolderIdType diFolder = new DistinguishedFolderIdType();
                BaseFolderIdType[] biArray = new BaseFolderIdType[1];
                diFolder.Id = DistinguishedFolderIdNameType.inbox;
                biArray[0] = diFolder;
    
                FindItemType fiFindItemRequest = new FindItemType();
                ItemResponseShapeType ipItemProperties = new ItemResponseShapeType();
                fiFindItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                ipItemProperties.BaseShape = DefaultShapeNamesType.AllProperties;
                
                PathToExtendedFieldType PidTagSenderSmtpAddress = new PathToExtendedFieldType();
                PidTagSenderSmtpAddress.PropertyTag = "0x5D01";
                PidTagSenderSmtpAddress.PropertyType = MapiPropertyTypeType.String;
    
                PathToExtendedFieldType PidTagConversationIndex = new PathToExtendedFieldType();
                PidTagConversationIndex.PropertyTag = "0x0071";
                PidTagConversationIndex.PropertyType = MapiPropertyTypeType.Binary;
    
                PathToExtendedFieldType PidTagConversationId = new PathToExtendedFieldType();
                PidTagConversationId.PropertyTag = "0x3013";
                PidTagConversationId.PropertyType = MapiPropertyTypeType.Binary;
    
                ipItemProperties.AdditionalProperties = new BasePathToElementType[3];
                ipItemProperties.AdditionalProperties[0] = PidTagSenderSmtpAddress;
    
    
                IndexedPageViewType ipvt = new IndexedPageViewType();
                ipvt.BasePoint = IndexBasePointType.Beginning;
                ipvt.MaxEntriesReturned = 10;
                ipvt.MaxEntriesReturnedSpecified = true;
                ipvt.Offset = 0;
    
                fiFindItemRequest.Item = ipvt;
                fiFindItemRequest.ItemShape = ipItemProperties;
                fiFindItemRequest.ParentFolderIds = biArray; 
    
                FindItemResponseType frFindItemResponse = esb.FindItem(fiFindItemRequest);
                if (frFindItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success)
                {
                    foreach (FindItemResponseMessageType firmtMessage in frFindItemResponse.ResponseMessages.Items)
                    {
                        Console.WriteLine("Number of Items Found : " + firmtMessage.RootFolder.TotalItemsInView);
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            foreach (MessageType miMailboxItem in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                GetItemType giType = new GetItemType();
                                giType.ItemIds = new BaseItemIdType[1];
                                giType.ItemIds[0] = miMailboxItem.ItemId;
                                giType.ItemShape = new ItemResponseShapeType();
                                giType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
                                giType.ItemShape.AdditionalProperties = new BasePathToElementType[2];
                                giType.ItemShape.AdditionalProperties[0] = PidTagConversationIndex;
                                
                                GetItemResponseType getItemResponse = esb.GetItem(giType);
                                ItemInfoResponseMessageType getItemResponseMessage =
                                    getItemResponse.ResponseMessages.Items[0]
                                    as ItemInfoResponseMessageType;
    
                                if (getItemResponseMessage != null)
                                {
                                    if (getItemResponseMessage.ResponseClass ==
                                        ResponseClassType.Success)
                                    {
                                        MessageType Message = (MessageType)getItemResponseMessage.Items.Items[0];
                                        Byte[] conversationIndex = Convert.FromBase64String(Message.ExtendedProperty[0].Item.ToString());
                                        Console.WriteLine(Message.Sender.Item.EmailAddress);
                                        Console.WriteLine(BitConverter.ToString(conversationIndex));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    
                    Console.WriteLine("Error Occured");
                    Console.WriteLine(frFindItemResponse.ResponseMessages.Items[0].MessageText.ToString());
                }
    Cheers
    Glen
    Friday, February 24, 2012 7:05 AM
  • i need to fetch the first mail and the last mail from each conversation between two people respectively. am not sure about the version of the exchange web service and is this the correct way to find the version of the EWS as i used in the coding?

    if the EWS is 2007 how can i fetch the required details which i have mentioned above.

    And please tell me if there is any alternative way to do.


    judo

    Monday, February 27, 2012 6:19 AM
  • >>about the version of the exchange web service and is this the correct way to find the version of the EWS as i used in the coding?

    If you have 2007 then you should be using the Exchange2007_SP1 enumeration this just points to the EWS Schema that's available on the server and the Schema wasn't update on Exchange 2007 sp2 or sp3.

    >> if the EWS is 2007 how can i fetch the required details which i have mentioned above.

     There is no easy answer for this in Exchange 2010 there is because operations where added and store functionality implemented to deal with the complexities see http://msdn.microsoft.com/en-us/library/ff631254%28v=exchg.80%29.aspx

      On Exchange 2007 with EWS you can get the Raw Mapi properties that represent the conversation information stored on each message (use a Mapi Editor to examine this further) like the Index and like the Conversation Topic. You then need to develop your own solution for determining which message is the first and last in the conversation using the conversationIndex which I've shown you how to access.  There's more information on the conversationIndex format here http://msdn.microsoft.com/en-us/library/ee202481(v=EXCHG.80).aspx 

    Cheers
    Glen

    Tuesday, February 28, 2012 1:37 AM
  • i am using EWS proxy version 2007 SP1

    i need to collect all the conversed messages between me and  my reportees and filter them just to retrieve the first  and the last conversed messages. Is there any way to collect conversed messages all alone by having ConversationIndex values in the format 01-CC-F5-B9-97-8F-51-04-81-D5-1B-7C-4A-39-8F-9C-AA-C7-EF-8F-BC-57 ?

    Guide me with ur code please


    judo

    Tuesday, February 28, 2012 10:23 AM