How I can get email headers programmatically from MS Exchange Server in Java?

有些话、适合烂在心里 提交于 2019-12-10 11:54:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!