none
How To Access Outlook CustomHeader Property in Exchange Services RRS feed

  • Question

  • I Need to Read Custom Header Properties for Outlook Mail Using Exchange Services.

    Whole Workflow:

    Step 1:Selected Mail : Set Custom Header In Outlook Mail Object

      MailItem mailItem = currentMailitem as MailItem;
    mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/NewProp", "TestData123");

    From Above Code When i Select again Same Mail I get Proper Value

    But,When i Read this message from Exchange Services I did't get this CustomProperty

    for that i used Below code

    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchNotFilter, new ItemView(1520));


                // FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(int.MaxValue));
                // Process each item.
                if (findResults.Items.Count > 0)
                {
                   
                    foreach (Item myItem in findResults.Items)
                    {

    //here  always myItem.ExtendedProperties.Count=0

                        foreach (var item in myItem.ExtendedProperties)

                        {

                        }

    }

    Can somone suggest me what is missing here

    Monday, March 14, 2016 2:37 PM

All replies

  • Hello Mayank,

    Did you save the item after setting the property value?

    Also you may try to synchronize folders with Exchange after adding a custom property. The OOM provides the NameSpace.SyncObjects property which returns a SyncObjects collection containing all Send\Receive groups.

    Public Sub Sync()  
     Dim nsp As Outlook.NameSpace  
     Dim sycs As Outlook.SyncObjects  
     Dim syc As Outlook.SyncObject  
     Dim i As Integer  
     Dim strPrompt As Integer  
     Set nsp = Application.GetNamespace("MAPI")  
     Set sycs = nsp.SyncObjects  
     For i = 1 To sycs.Count  
     Set syc = sycs.Item(i)  
     strPrompt = MsgBox("Do you wish to synchronize " & syc.Name &"?", vbYesNo)  
     If strPrompt = vbYes Then  
     syc.Start  
     End If  
     Next  
    End Sub

    Do you see changes on the server after?

    Monday, March 14, 2016 3:40 PM
  • Hello Eugene,

    Thanks For your replay.

    Yes I save the property value but it didn't work.

    when i sync mail it sync process which mail has changed,but i required only those mail which mail has set this property so i can take further action only those mail not all changed mail.

     it will be great if you can provide more clarification on your above code?

    Thanks in advance

     

    Monday, March 14, 2016 5:20 PM
  • Hi, Mayank_55

    According to your description, as far as I know that PropertyAccessor.SetProperty is saved with the MailItem.Save method, so I suggest that you could make sure that you could get use the PropertyAccessor.GetProperty method to read a MAPI property that belongs to a MailItem:

    Sub DemoPropertyAccessorSetProperty()
     Dim myProp As String
     Dim myValue As Variant
     Dim oMail As Outlook.MailItem
     Dim oPA As Outlook.propertyAccessor
     'Get first item in the inbox
     Set oMail = _
     Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
     'Name for custom property using the MAPI string namespace
     myProp = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/NewProp"
     myValue = "TestData123"
     'Set value with SetProperty call
     'If the property does not exist, then SetProperty
     'adds the property to the object when saved.
     'The type of the property is the type of the element
     'passed in myValue.
     On Error GoTo ErrTrap
     Set oPA = oMail.propertyAccessor
     oPA.SetProperty myProp, myValue
     
     'Save the item
     oMail.Save
     Exit Sub
    ErrTrap:
     Debug.Print Err.Number, Err.Description
    End Sub
    
    Sub DemoPropertyAccessorGetProperty()
     
     Dim PropName, Header As String
     
     Dim oMail As Object
     
     Dim oPA As Outlook.propertyAccessor
     
     'Get first item in the inbox
     
     Set oMail = Application.Session.GetDefaultFolder(olFolderInbox).Items(1)
     
     'PR_TRANSPORT_MESSAGE_HEADERS
     
     PropName = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/NewProp"
     
     'Obtain an instance of PropertyAccessor class
     
     Set oPA = oMail.propertyAccessor
     
     'Call GetProperty
     
     Header = oPA.GetProperty(PropName)
     
     Debug.Print (Header)
     
    End Sub


    For more information, click here to refer about PropertyAccessor Object (Outlook)

    Tuesday, March 15, 2016 7:00 AM
  • Hello David,

    Yes Above Code Is working fine with Outlook Mail Object,But I can not Get This Header in Exchange Service Mail Object when i check ExtendedProperties is always Null,

    How we access Outlook Properties in Exchange Mail Service Object.

    FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchNotFilter, new ItemView(1520));


                // FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(int.MaxValue));
                // Process each item.
                if (findResults.Items.Count > 0)
                {
                   
                    foreach (Item myItem in findResults.Items)
                    {

    //here  always myItem.ExtendedProperties.Count=0

                        foreach (var item in myItem.ExtendedProperties)

                        {

                        }

    }


    Basically I want to store CustomHeader Property in Outlook Object Model (MailItem Object) and Want to access same Property Value in Exchange Service Object (EmailMessage Object)
    • Edited by Mayank_55 Tuesday, March 15, 2016 8:41 AM
    Tuesday, March 15, 2016 7:48 AM
  • Hi, Mayank_55

    This is the forum to discuss questions and feedback for Visual Studio Tools for Office (VSTO), since this issue is more related to Exchange Service, I'll move your question to the MSDN forum for Exchange Server Development

    https://social.msdn.microsoft.com/Forums/exchange/en-US/home?forum=exchangesvrdevelopment

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. 

    Thanks for your understanding.
    Friday, March 18, 2016 9:41 AM