none
Using Exchange Web Services API Insert Item in Conversations History Folder in Outlook RRS feed

  • Question

  • Hi,

    I was able to get the Conversation History Folder in Outlook using the Exchange Server API's and using the below msdn link.

    http://msdn.microsoft.com/en-us/library/hh243707(v=office.14).aspx

    Now what i want is to insert the items in it.

    Basically i am capturing the Lync Conversations and want to add them to Conversations History Folder.

    I am able to get the Lync Conversations using Lync Apis and looking for a way to Insert them to the Conversations History Folder in Outlook using Exchange Web Services.

    Please help.

    Thanks

    Jaspreet Singh

    Wednesday, October 30, 2013 11:59 AM

Answers

  • The Conversation Class doesn't have anything to do with Lync its used for Email conversations (or threaded\grouped email conversations).

    There are no strongly typed objects for Lync Conversations so to Create one you'll need to use the EmailMessage class and then change the ItemClass. Lync uses a number of undocumented extended properties so you'll need to use a Mapi Editor like Outlookspy or MFCMapi to work out what all the properties setting and values you need are depending on what type of things your trying to create. Eg for a really basic conversation

                Folder cnvFolder = Folder.Bind(service, WellKnownFolderName.ConversationHistory);
                EmailMessage NewCnvItem = new EmailMessage(service);
                NewCnvItem.ItemClass = "IPM.Note.Microsoft.Conversation";
                NewCnvItem.ToRecipients.Add("user1@domain.com");
                NewCnvItem.ToRecipients.Add("user2@domain.com");
                NewCnvItem.Subject = "Conversation with Blah Blah";
                ExtendedPropertyDefinition Direction = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Direction.{2DA4DF04-920D-4b0b-A1D7-5FC9D21857FE}", MapiPropertyType.Integer);
                ExtendedPropertyDefinition Modalities = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Modalities.{0885EA21-B7A5-4050-BFDB-AD46DE1D6A87}", MapiPropertyType.Integer);
                ExtendedPropertyDefinition IsCustomSubject = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "IsCustomSubject.{703DC3CB-8F24-4e3f-932F-206233656759}", MapiPropertyType.Integer);
                ExtendedPropertyDefinition DisplayDirection = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "DisplayDirection.{4255C773-497E-4b5e-9205-F360CAF3316A}", MapiPropertyType.String);
                ExtendedPropertyDefinition RemoteParty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "RemoteParty.{664AD731-19D0-4344-93FD-682FE0440D95}", MapiPropertyType.String);
                ExtendedPropertyDefinition HistoryInfo = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "HistoryInfo.{553F3F08-FC28-41db-859E-63457407F806}", MapiPropertyType.String);
                ExtendedPropertyDefinition ConversationXml = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "ConversationXml.{CA2F170A-A22B-4f0a-B899-93439DEC3FBC}", MapiPropertyType.String);
                
                String cnvXML = "<conversationsxmlns=\"http://schemas.microsoft.com/2008/10/sip/convItems\"minSupportedClientVersion=\"3.0.0.0\"><conversationXml></conversationXml></conversations>";
                NewCnvItem.Body = new MessageBody(Microsoft.Exchange.WebServices.Data.BodyType.HTML, "test");
                NewCnvItem.SetExtendedProperty(ConversationXml, cnvXML);
                NewCnvItem.SetExtendedProperty(Direction,1);
                NewCnvItem.SetExtendedProperty(Modalities,1);
                NewCnvItem.SetExtendedProperty(IsCustomSubject,0);
                NewCnvItem.SetExtendedProperty(DisplayDirection,"Incoming");
                NewCnvItem.SetExtendedProperty(RemoteParty,"sip:user2@domain.com");
                NewCnvItem.SetExtendedProperty(HistoryInfo,"sip:user2@domain.com");
                NewCnvItem.From = new Microsoft.Exchange.WebServices.Data.EmailAddress(" Test", "user2@domain.com");
                NewCnvItem.SetExtendedProperty(new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer), "1");
                NewCnvItem.Save(cnvFolder.Id);
    Cheers
    Glen
     
    Thursday, October 31, 2013 5:38 AM

All replies

  • Hi Jaspreet,

    you can use two main ways to insert items into a folder. Either binding the folder and using its method, or using the analogous method of the ExchangeService object. Both are well documented in the EWS Managed Api documentation. The ExchangeService object has methods to do bulk-operations, which may come in handy if speed matters.

    To be able to use Lync Conversations, you will likely have to convert them to into a Conversation Class object of the EWS MA Api, before inserting them into the folder.

    Cheers,
    Fred


    There's no place like 127.0.0.1

    Wednesday, October 30, 2013 1:46 PM
  • The Conversation Class doesn't have anything to do with Lync its used for Email conversations (or threaded\grouped email conversations).

    There are no strongly typed objects for Lync Conversations so to Create one you'll need to use the EmailMessage class and then change the ItemClass. Lync uses a number of undocumented extended properties so you'll need to use a Mapi Editor like Outlookspy or MFCMapi to work out what all the properties setting and values you need are depending on what type of things your trying to create. Eg for a really basic conversation

                Folder cnvFolder = Folder.Bind(service, WellKnownFolderName.ConversationHistory);
                EmailMessage NewCnvItem = new EmailMessage(service);
                NewCnvItem.ItemClass = "IPM.Note.Microsoft.Conversation";
                NewCnvItem.ToRecipients.Add("user1@domain.com");
                NewCnvItem.ToRecipients.Add("user2@domain.com");
                NewCnvItem.Subject = "Conversation with Blah Blah";
                ExtendedPropertyDefinition Direction = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Direction.{2DA4DF04-920D-4b0b-A1D7-5FC9D21857FE}", MapiPropertyType.Integer);
                ExtendedPropertyDefinition Modalities = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "Modalities.{0885EA21-B7A5-4050-BFDB-AD46DE1D6A87}", MapiPropertyType.Integer);
                ExtendedPropertyDefinition IsCustomSubject = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "IsCustomSubject.{703DC3CB-8F24-4e3f-932F-206233656759}", MapiPropertyType.Integer);
                ExtendedPropertyDefinition DisplayDirection = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "DisplayDirection.{4255C773-497E-4b5e-9205-F360CAF3316A}", MapiPropertyType.String);
                ExtendedPropertyDefinition RemoteParty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "RemoteParty.{664AD731-19D0-4344-93FD-682FE0440D95}", MapiPropertyType.String);
                ExtendedPropertyDefinition HistoryInfo = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "HistoryInfo.{553F3F08-FC28-41db-859E-63457407F806}", MapiPropertyType.String);
                ExtendedPropertyDefinition ConversationXml = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "ConversationXml.{CA2F170A-A22B-4f0a-B899-93439DEC3FBC}", MapiPropertyType.String);
                
                String cnvXML = "<conversationsxmlns=\"http://schemas.microsoft.com/2008/10/sip/convItems\"minSupportedClientVersion=\"3.0.0.0\"><conversationXml></conversationXml></conversations>";
                NewCnvItem.Body = new MessageBody(Microsoft.Exchange.WebServices.Data.BodyType.HTML, "test");
                NewCnvItem.SetExtendedProperty(ConversationXml, cnvXML);
                NewCnvItem.SetExtendedProperty(Direction,1);
                NewCnvItem.SetExtendedProperty(Modalities,1);
                NewCnvItem.SetExtendedProperty(IsCustomSubject,0);
                NewCnvItem.SetExtendedProperty(DisplayDirection,"Incoming");
                NewCnvItem.SetExtendedProperty(RemoteParty,"sip:user2@domain.com");
                NewCnvItem.SetExtendedProperty(HistoryInfo,"sip:user2@domain.com");
                NewCnvItem.From = new Microsoft.Exchange.WebServices.Data.EmailAddress(" Test", "user2@domain.com");
                NewCnvItem.SetExtendedProperty(new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer), "1");
                NewCnvItem.Save(cnvFolder.Id);
    Cheers
    Glen
     
    Thursday, October 31, 2013 5:38 AM
  • Hi Glen,

    Thanks for your reply.

    Actually I am getting the conversations using Lync API, by subscribing to Lync Api events.

    and getting only one conversation at a time, like I am subscribing to each and every conversation.

    I am not sure how I can apply the above code to save those conversations to Conversation History Folder.

    Thanks

    Thursday, October 31, 2013 5:44 PM
  • >> I am not sure how I can apply the above code to save those conversations to Conversation History Folder.

    I guess the first question is why are you trying to do this ? if lync is configured properly then it will do this for you.

    >> I am not sure how I can apply the above code to save those conversations to Conversation History Folder.

     As far as I know there properties that link uses in EWS aren't documented. So basically if you want to use what you have in the Lync API you'll need to map the properties yourself (eg Lync API modality would equal the EWS ExtendedPropertyDefinition Modalities). So you'll need a working Lync Client that saves the conversation history to Conversation folder and then you'll need to look at the properties on existing conversation items (this is where a MAPI editor like OutlookSpy or MFCmapi will need to be used) and then reverse engineer from there against what you see in the LyncAPI.

      You might want ask a question in the Lync Forum to see if someone else has done the property mapping before. Otherwise unfortunately this is the only way you'll be able to achieve it.

      The code I posted is just a simple example of creating a single conversation item. If your going to create EWS Items you'll need to get comfortable using the EWS Managed API eg http://msdn.microsoft.com/EN-US/library/ff597939(v=exchg.80).aspx

    Cheers
    Glen

    Friday, November 1, 2013 6:41 AM
  • Hi Glen,

    Thanks for your reply , i tried to use the code but got the following error.

    {Microsoft.Exchange.WebServices.Data.ServiceVersionException: Enumeration value ConversationHistory in enumeration type WellKnownFolderName is only valid for Exchange version Exchange2013 or later.

    I think we are using Exchange version 2010.

    Can you please help.

    Thanks

    Jaspreet Singh

    Friday, November 8, 2013 9:12 AM
  • In 2010 you can't directly bind to the folder so you will need to use FindFolder to first search for the Folder eg

           static Folder FindConversationHistory(ExchangeService service,String MailboxName) {
               Folder cnvFolder = null;
               FolderView fv = new FolderView(1);
               SearchFilter sf = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, "conversation history");
               FolderId mbRoot = new FolderId(WellKnownFolderName.MsgFolderRoot, MailboxName);
               FindFoldersResults ffResult = service.FindFolders(mbRoot, sf, fv);
               if (ffResult.Folders.Count == 1) {
                   cnvFolder = ffResult.Folders[0];
               }
               return cnvFolder;
    
                
            }
    Cheers
    Glen
    Monday, November 11, 2013 3:19 AM
  • Thanks a lot Glen for your help. It really helped !!!.

    Thanks

    Jaspreet

    Wednesday, November 27, 2013 5:36 AM
  • Hello

    I tried the code sample given above.  Everything works fine for the most part.

    However, the Lync client synchronizes its "Conversations"  with the Conversation History folder.  This is fine, but in the Lync client conversation, I don't see the body text of the conversation item that I created.  

    i.e. Start a conversation through the Lync client, in the Outlook conversation history folder,  I see an item in the conversation history folder, where the body of the outlook item includes the im text.

    Now, if I create an item in the folder using the API and properties above (I set the body text), I can see the body text in outlook, but when it gets synchronized to the Lync client, in the Lync client conversation item, I don't see any text in the conversation.

    Any ideas?

    Thanks

    Monday, January 13, 2014 8:18 PM
  • I think you'll find the Lync client probably uses ConversationXml property but as I mentioned there is no documentation on any of this or the format of the XML for this property so the only way of finding out would be to play with the properties your self using a MAPI Editor like MFCMapi.

    Cheers
    Glen

    Tuesday, January 14, 2014 4:34 AM