问题
I can't get access to headers in email. At that moment I can get only ExtendedPropertyCollection object, but I don't know how to work with it.
ItemEvent item = (ItemEvent) event;
EmailMessage message = EmailMessage.bind(args.getSubscription().getService(), item.getItemId());
ExtendedPropertyCollection extendedProperties = ((ExtendedPropertyCollection) message.getExtendedProperties());
UPDATE:
The result code in Java looks like:
PropertySet propertySet = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent);
EmailMessage message = EmailMessage.bind(args.getSubscription().getService(), item.getItemId(), propertySet);
String emailTextWithHeaders = new String(message.getMimeContent().getContent());
回答1:
There are two ways to do that you should be able to access the InternetMessageHeader collection vai the EmailMessage class https://github.com/OfficeDev/ews-java-api/blob/master/src/main/java/microsoft/exchange/webservices/data/InternetMessageHeader.java
The other way is to use the PR_TRANSPORT_MESSAGE_HEADERS extended property eg
ExtendedPropertyDefinition PR_TRANSPORT_MESSAGE_HEADERS = new ExtendedPropertyDefinition(0x007D, MapiPropertyType.String);
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties) { PR_TRANSPORT_MESSAGE_HEADERS};
EmailMessage message = EmailMessage.bind(args.getSubscription().getService(), item.getItemId(),psPropSet);
Cheers Glen
来源:https://stackoverflow.com/questions/27507359/how-i-can-get-email-headers-programmatically-from-ms-exchange-server-in-java