访问Outlook和Exchange Web服务:验证错误401

问题描述:

当与Exchange Web服务的帮助下访问Outlook,我得到一个验证错误401访问Outlook和Exchange Web服务:验证错误401

以下是我的代码连接到Outlook:

public static void usingEWS(){ 
       try { 
        System.out.println("***********************************************"); 

        //System.setProperty("javax.net.ssl.trustStore", "C:\\Users\\vermad\\Downloads\\Softz\\jssecacerts"); 
        System.setProperty("javax.net.ssl.trustStore","C:\\Users\\username\\Downloads\\Softz\\jssecacerts"); 

        ExchangeCredentials credentials = new WebCredentials("[email protected]","password","domain.com"); 
        service.setCredentials(credentials); 
        service.setUrl(new URI("https://vabcxdp/EWS/Exchange.asmx")); 

      ItemView view = new ItemView (5); 
      //System.out.println(service.getCredentials()); 
      //System.out.println("2"); 
//getting error here 
      FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox, view); 

      for(Item item : findResults.getItems()){ 
      item.load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent)); 
      System.out.println("id==========" + item.getId()); 
      System.out.println("sub==========" + item.getSubject()); 
      System.out.println("sub==========" + item.getMimeContent()); 
      } 

     } catch (Exception mex) { 
      mex.printStackTrace(); 
     } 
     } 
+0

欢迎来到Stack Overflow!我编辑了你的问题的标题,以便更加简洁和现场。我还修复了一些错误类型并将代码示例缩进了4个空格,以便正确呈现 - 请参阅编辑帮助以获取有关格式化的更多信息。祝你好运! – Wtower

我我能够通过使用系统用户名而不是用户名解决问题,例如:amukati而不是用户名:[email protected]