最近在做exchange 2013开发,需要查所有exchange 2013用户有收到邮件时都响应某功能,
现在可以监控某一个用户,当监控所有用户时报 未声明“SubscribeToAllFolders”特性。 错误
以下是代码:
public class NewMailNotification {
public static void main(String[] args) {
try {
Service service = new Service("https://test.cn/EWS/Exchange.asmx", "administrator", "123456");
String newWatermark = null;
PullSubscription subscription = new PullSubscription(true, EventType.NEW_MAIL);
// initial subscribe
SubscribeResponse subscribeResponse = service.subscribe(subscription);
while (true) {
Thread.currentThread().join(1000);
GetEventsResponse eventsResponse = service.getEvents(subscribeResponse);
Notification notification = eventsResponse.getNotification();
for (int i = 0; i < notification.getEvents().size(); i++) {
newWatermark = notification.getEvents().get(i).getWatermark();
System.out.println("newWatermark = " + newWatermark);
if (notification.getEvents().get(i) instanceof NewMailEvent) {
NewMailEvent newMailEvent = (NewMailEvent) notification.getEvents().get(i);
ItemId itemId = (ItemId) newMailEvent.getId();
Message message = service.getMessage(itemId);
System.out.println(message.getSubject());
System.out.println(message.getReceivedTime());
Method[] methods = message.getClass().getMethods();
for(Method method : methods){
if(method.getName().contains("get") && method.getParameterCount() == 0){
Object o = null;
try {
o = method.invoke(message);
if(o == null){
//System.out.println(method.getName() + " --> null");
}else{
//System.out.println(method.getName() + " --> " + o.toString());
}
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
// resubscribe with new watermark
subscription.setWatermark(newWatermark);
subscribeResponse = service.subscribe(subscription);
}
} catch (ServiceException e) {
System.out.println(e.getMessage());
System.out.println(e.getXmlMessage());
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
请问SubscribeToAllFolders权限怎么赋予