none
exchange 2013 sp1 ews - using extended mapi properties RRS feed

  • Question

  • Hi All,

    trying to use extended mapi properties. i've been asked to sort out a way of returning all items in an inbox that are not replied to or forwarded after 48 hours, by category. i'm working my way through Glen Scales' examples on his great blog, here:

    http://gsexdev.blogspot.co.uk/2012/02/ews-managed-api-and-powershell-how-to.html

     th mapi property i want to use is PR_LAST_VERB_EXECUTED

    https://msdn.microsoft.com/en-us/library/office/cc841968.aspx

    but i am struggling, somewhat. this is the (working) code i've got to retrieve an extended mapi property for a mail item in the inbox:

    $inbox = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid)
    
    
    	 $psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)  
    	 $PidTagSubject = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x0037,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::string);  
    	 $psPropSet.Add($PidTagSubject)  
         
    
    
    
        #Define ItemView to retrive just 10 Items  
    	 $ivItemView =  New-Object Microsoft.Exchange.WebServices.Data.ItemView(10)  
    	 $fiItems = $service.FindItems($Inbox.Id,$ivItemView)  
    	 [Void]$service.LoadPropertiesForItems($fiItems,$psPropset)  
    	 foreach($Item in $fiItems.Items){  
    	     "RecivedDate : " + $Item.DateTimeReceived   
    	     "Subject     : " + $Item.Subject    
             "category    : " + $Item.categories
             	 
    	$msMessage = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service,$Item.Id,$psPropSet)    
    	  
    	$SubjectVal = $null  
    	if($msmessage.TryGetProperty($PidTagSubject,[ref]$SubjectVal)){  
         "Extended Property : " + $SubjectVal  
    	 }  
    
    
    
    }  

    works perfectly; it outputs exactly what you'd expect:

    RecivedDate : 01/15/2017 19:25:45
    Subject     : red item 2
    category    : Red category
    Extended Property : red item 2

    well yeah, it would; it's just Glen's code.

    when i edit it to retrieve the property i want, i get a fail. i change the line that defines $PidTagSubject to:

    $PidTagSubject = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x1081,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Long); 

    and i get:

    RecivedDate : 01/15/2017 19:25:45
    Subject     : red item 2
    category    : Red category
    Exception calling "Bind" with "3" argument(s): "The extended property attribute combination is invalid."
    At C:\Users\administrator.EX2K13LONE\Documents\scratchewsold.ps1:50 char:2
    +     $msMessage = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($service, ...
    +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ServiceResponseException

    now using mfcmapi i can see that the property is as follows:

    so i would expect the returned extended mapi property to be "102"...

    what am i doing wrong?


    Tuesday, January 17, 2017 7:29 PM

Answers

  • You property definition is wrong eg the Datatype should be Integer instead of Long.

    $PidTagSubject = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x1081,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer); 

    The reason for this is because of the age of Mapi there is a explanation in https://msdn.microsoft.com/en-us/library/office/aa564843(v=exchg.150).aspx  "In Microsoft .NET, a Long is a 64-bit signed integer, while in MAPI and COM, a Long is a 32-bit integer. Most developers will use the Microsoft.NET Framework to develop Exchange Web Services client applications. Therefore, the .NET naming is used instead of the MAPI naming. For example, the PR_MESSAGE_FLAGS MAPI property, 0x0E07, is a PT_LONG type. In .NET, this is considered an integer. An extended property for PR_MESSAGE_FLAGS is defined as <t:ExtendedFieldURI PropertyTag="0x0E07" PropertyType="Integer"/>."

    Cheers
    Glen

    • Marked as answer by ishmael.whale Wednesday, January 18, 2017 7:42 AM
    Wednesday, January 18, 2017 1:16 AM

All replies

  • You property definition is wrong eg the Datatype should be Integer instead of Long.

    $PidTagSubject = new-object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x1081,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Integer); 

    The reason for this is because of the age of Mapi there is a explanation in https://msdn.microsoft.com/en-us/library/office/aa564843(v=exchg.150).aspx  "In Microsoft .NET, a Long is a 64-bit signed integer, while in MAPI and COM, a Long is a 32-bit integer. Most developers will use the Microsoft.NET Framework to develop Exchange Web Services client applications. Therefore, the .NET naming is used instead of the MAPI naming. For example, the PR_MESSAGE_FLAGS MAPI property, 0x0E07, is a PT_LONG type. In .NET, this is considered an integer. An extended property for PR_MESSAGE_FLAGS is defined as <t:ExtendedFieldURI PropertyTag="0x0E07" PropertyType="Integer"/>."

    Cheers
    Glen

    • Marked as answer by ishmael.whale Wednesday, January 18, 2017 7:42 AM
    Wednesday, January 18, 2017 1:16 AM
  • That's Brilliant - cheers again Glen. 

    i have a lot to learn... :D

    
    Wednesday, January 18, 2017 7:42 AM