问题
We have created extendedProperties on emails using val uId = getUniqueId();
val emailExtendedPropDef = new ExtendedPropertyDefinition(uId,"uniqueId", MapiPropertyType.String)
try {
email.setExtendedProperty(emailExtendedPropDef, uId.toString)
email.sendAndSaveCopy()
} catch {
case e: Exception =>
error(s"Exception in setting extended property for user $from", e)
throw e
}
Now we want to iterate over the emails in sent folder and go over the extendedProperties for the emails that have been set
val view = new ItemView(1000)
var extendedPropertyIndex = 0
var bodyList = new ListBuffer[String]()
val propertySet = new PropertySet(BasePropertySet.FirstClassProperties
try {
val findResults = service.findItems(WellKnownFolderName.SentItems, view)
if (findResults.getTotalCount > 0) {
val iterator = findResults.getItems().iterator()
while(iterator.hasNext) {
val item = iterator.next()
val extendedPropertyCollection = item.getExtendedProperties()
println("count is "+extendedPropertyCollection.getCount())
if (extendedPropertyCollection.getCount() > 0)
{
//do some processing
}
}
}
}
We are able to successfully retrieve the items but not their extended properties not sure why
We have been getting the count as 0 eventhough we know for these items we have set the extendedProperty using the above logic ......
It will be of great help if someone could point us in the right direction on why we are receiving 0 count for the extended properties and also our requirement is to retrieve all the emails with extendedProperties set
Update : tried with these options
val emailIdPropDef = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings,"uniqueId", MapiPropertyType.String)
val propertySet = new PropertySet(BasePropertySet.FirstClassProperties, emailIdPropDef)
view.setPropertySet(propertySet)
But still no luck any pointer in the right direction will be of great help
回答1:
Exchange will only return the extended properties you request it to return. So you need to add the extended property to the PropertySet your using in the FindItems operation and it will then get returned if it has been set on any objects that FindItem returns.eg this property
val emailExtendedPropDef = new ExtendedPropertyDefinition(uId,"uniqueId", MapiPropertyType.String)
needs to be added to this Propertyset
val propertySet = new PropertySet(BasePropertySet.FirstClassProperties)
and that property set should be used on this ItemView
val view = new ItemView(1000)
val.PropertySet = propertySet
来源:https://stackoverflow.com/questions/50847448/how-to-retrieve-the-extendedproperties-associated-with-emails-in-the-sent-folder